要将dwu_bqf_item_day 中的lastyear_value 更新为bq_data_lastyear 表中的lastyearvalue值。
dwu_bqf_item_day (DATA_DATE,ITEM_CODE,CORP_CODE)等字段
bq_data_lastyear (DATA_DATE,ITEM_CODE,CORP_CODE)等字段
语句是以下这样写的:
Update dwu_bqf_item_day a
Set a.lastyear_value = (select b.lastyearvalue
from bq_data_lastyear b
where a.corp_code = b.corp_code
and a.item_code = b.item_code)
Where exists (select 1
from bq_data_lastyear b
where a.corp_code = b.corp_code
and a.item_code = b.item_code)
------解决方案--------------------
Update dwu_bqf_item_day a
Set a.lastyear_value = (select b.lastyearvalue
from bq_data_lastyear b
where a.corp_code = b.corp_code
and a.item_code = b.item_code and rownum=1)
Where exists (select 1
from bq_data_lastyear b
where a.corp_code = b.corp_code
and a.item_code = b.item_code)
------解决方案--------------------
你的这个子查询返回多行结果
select b.lastyearvalue
from bq_data_lastyear b
where a.corp_code = b.corp_code
and a.item_code = b.item_code
可以是有聚合函数,比如max() min() ……
也可以像一楼一样
------解决方案--------------------