想要将一列数据复制到SQL中的另一列表列中.使用此查询不起作用


UPDATE temp_test
 SET country_i = (select a.country_code from temp_test2 a,temp_test c
                       where c.country_i is null and 
            a.active = 'A' and c.created_by = a.partner_by)

您可以使用 MERGE 语句。这很容易理解。

MERGE INTO temp_test t
USING temp_test2 u
ON (t.created_by = u.partner_by)
WHEN MATCHED THEN 
UPDATE SET
   t.country_i = u.country_code
   WHERE t.country_i IS NULL
   AND   u.active = 'A';
UPDATE temp_test c SET country_i = (select a.country_code from temp_test2 a where a.active = 'A' and c.created_by = a.partner_by) where c.country_i is null;

在我看来,它应该有效...

最新更新