首页 > 解决方案 > SQL使用IIF填空

问题描述

我有几列和几个这样的数据

sms_type        ID              fullname
incoming        2036037         NULL
outgoing        2036037         Jason Sayre

如果 ID 列匹配,我喜欢用相同的名称 (Jason Sayre) 在 fullname 列中填充 NULL
谢谢。

标签: sqlsql-server

解决方案


您可以使用coalesce()和窗口函数:

select t.*,
       coalesce(fullname, max(fullname) over (partition by id)) as imputed_fullname
from t;

推荐阅读