1

对于以下查询获得的所有结果,如何将 a.age 和 b.age 更新为 32。临时列是“CID”,如下例所示

select * 
  from (SELECT ROW_NUMBER() 
               OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
          FROM (select CUST_NAME,AGE,CITY,COLUMNB
                  from SOMETABLE 
                 where date = '26-jULY-2012'))a 
  RIGHT join (select * 
                from (SELECT ROW_NUMBER() 
                             OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
                       FROM (select CUST_NAME,AGE,CITY,COLUMNB
                               from SOMETABLE2 
                              where date = '26-jULY-2012')))b 
         on a.CID=b.CID 
   and a.CUST_NAME=b.CUST_NAME  
 ORDER BY a.CUST_NAME,A.CID,a.COLUMNB;
4

1 回答 1

0
update sometable
set age = 32
where cid in (
select a.cid
  from (SELECT ROW_NUMBER() 
               OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
          FROM (select CUST_NAME,AGE,CITY,COLUMNB
                  from SOMETABLE 
                 where date = '26-jULY-2012'))a 
  RIGHT join (select * 
                from (SELECT ROW_NUMBER() 
                             OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
                       FROM (select CUST_NAME,AGE,CITY,COLUMNB
                               from SOMETABLE2 
                              where date = '26-jULY-2012')))b 
         on a.CID=b.CID 
   and a.CUST_NAME=b.CUST_NAME  
)
;




update sometable2
set age = 32
where cid in (
select b.cid
  from (SELECT ROW_NUMBER() 
               OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
          FROM (select CUST_NAME,AGE,CITY,COLUMNB
                  from SOMETABLE 
                 where date = '26-jULY-2012'))a 
  RIGHT join (select * 
                from (SELECT ROW_NUMBER() 
                             OVER (PARTITION BY CUST_NAME ORDER BY CUST_NAME) AS CID,CUST_NAME,AGE,CITY,COLUMNB 
                       FROM (select CUST_NAME,AGE,CITY,COLUMNB
                               from SOMETABLE2 
                              where date = '26-jULY-2012')))b 
         on a.CID=b.CID 
   and a.CUST_NAME=b.CUST_NAME  
)
;
于 2012-08-15T16:24:00.127 回答