我想使用具有相同客户端编号的非空白列更新客户端表中的空白名称列。你知道我应该如何修改下面的SQL吗?谢谢,
UPDATE CLIENT
SET NAME=(SELECT NAME FROM CLIENT WHERE (NAME IS NOT NULL AND NAME<>'') )
FROM CLIENT C1, CLIENT C2
WHERE (NAME IS NULL OR NAME='') AND C1.CLIENT_NO=C2.CLIENT_NO
答案 0 :(得分:1)
I would recommend using window functions for this purpose:
with toupdate as (
select c.*, max(name) over (partition by client_no) as maxname
from client c
)
update toupdate
set name = maxname
where name is null or name = '';