有一个表有一个空列,我需要用row_number()填充这个列,并根据其他表中的值对其排序。我的CTE可以工作,但我不能更新第二个表。
这是CTE(有效)with testy(a, b, c) as (select t1.empno, t2.birthdate, ROW_NUMBER() OVER(ORDER BY t2.birthdate DESC) as order_by_id from test_tab as t1 join employee as t2 on t2.empno = t1.empno)
此请求更新列但不起作用
with testy(a, b, c) as (select
t1.empno
, t2.birthdate
, ROW_NUMBER() OVER(ORDER BY t2.birthdate DESC) as order_by_id
from test_tab as t1 join employee as t2 on t2.empno = t1.empno)
update test_tab
set test_tab.id = testy.b
where test_tab.empno = testy.a
2条答案
按热度按时间zlhcx6iw1#
如果您在Db2上执行LUW,则支持
UPDATE FROM SELECT
语法。MERGE
也可用于其它情况。请注意,您的子选择不能包含
EMPNO
的重复项。| EMPNO公司|识别码|
| - -|- -|
| 10个|2个|
| 二十个|一个|
fiddle
vdgimpew2#
您的查询应该会得到一个错误,指出testy.B是未知的
但是你可以做