0

我正在使用以下查询来更新列但无法更新。

update table1
 set month_0val = (select v1.sumvalue 
 from ( select r1.reg_id, sum(backbook.bal) as sumvalue
 from  table2 backbook , table3 s , table4 r1
 where month(backbook.Date_AsOf) = month(s.MONTH_AS_OF - INTERVAL 12 MONTH) and year(backbook.Date_AsOf) =  year(s.MONTH_AS_OF - INTERVAL 12 MONTH)  and  backbook.a_region_id = r1.region_code
 and r1.org_id = org_id and  backbook.A_ProdType_Code != 25  and s.SC_ID = sc_id group by backbook.A_Region_ID ) v1
 where v1.reg_id = table1.Region);

甚至内部查询也会返回结果。

请帮忙。

4

1 回答 1

0
UPDATE table1, ( 
            select r1.reg_id, sum(backbook.bal) as sumvalue
            from  table2 backbook , table3 s , table4 r1
            where month(backbook.Date_AsOf) = month(s.MONTH_AS_OF - INTERVAL 12 MONTH) 
              and year(backbook.Date_AsOf) =  year(s.MONTH_AS_OF - INTERVAL 12 MONTH)  
              and  backbook.a_region_id = r1.region_code
              and r1.org_id = org_id 
              and  backbook.A_ProdType_Code != 25  
              and s.SC_ID = sc_id 
            group by backbook.A_Region_ID 
            ) v1
SET table1.month_0val = v1.sumvalue
WHERE v1.reg_id = table1.Region;
于 2012-07-26T07:37:31.620 回答