0

我必须表 T1 和 T2。我想从 T1 更新 T2 中的第四列。查询是

update t1 
set   t1.price=(select price from (select t1.price 
                            from t2 
                            where t1.customer=t2.customer and t1.sku=t2.sku and 
                                  t1.weekno= t2.weekno) where rownum=1)

但它抛出错误无效标识符 t1.weekno。我尝试了其他几种方法,但每次我都面临同样的问题。如果你能帮助我,我将不胜感激。谢谢

PS:我们正在处理 500 万条记录。

4

2 回答 2

1

您的查询的问题是您t1.price在相关子查询的选择语句中引用。有几种方法可以解决这个问题。

一种选择是为此使用MERGE

merge
into t1
using   (
        select  t1.customer as updatedCustomer, t2.sku updatedsku, t2.weekno updatedweekno, t2.price updatedPrice
        from    t1
            join    t2
                on      t1.customer = t2.customer and t1.sku=t2.sku and 
                              t1.weekno= t2.weekno
        )
on      (customer = updatedCustomer and sku = updatedsku and weekno = updatedweekno)
when matched then
update
set     price = updatedPrice;

或者,您可以更新相关子查询以使用 t2.price:

update t1 
set price = (select t2.price 
             from t2 
             where t1.customer=t2.customer and t1.sku=t2.sku and 
                              t1.weekno= t2.weekno and rownum = 1)
于 2013-07-21T19:48:39.437 回答
0

您需要将 t1 添加到子查询的 from 子句中:

select t1.price 
                            from t1,t2
                            where t1.customer=t2.customer and t1.sku=t2.sku and 
                                  t1.weekno= t2.weekno
于 2013-07-21T19:26:36.730 回答