sql - SQL使用IIF填空
问题描述
我有几列和几个这样的数据
sms_type ID fullname
incoming 2036037 NULL
outgoing 2036037 Jason Sayre
如果 ID 列匹配,我喜欢用相同的名称 (Jason Sayre) 在 fullname 列中填充 NULL
谢谢。
解决方案
您可以使用coalesce()
和窗口函数:
select t.*,
coalesce(fullname, max(fullname) over (partition by id)) as imputed_fullname
from t;
推荐阅读
- database - 如何存储从 websockets 收到的消息
- xcode - Big Sur 上的 QuickLook 插件 UTI 无法正常工作
- python - 如何使用for循环将来自各种csv的列添加到新的csv
- rust - 添加 Rust 和 Webassembly
- spring-data-elasticsearch - spring-data-elasticsearch 对 elasticsearch 版本 7.14 的支持
- excel - Excel DisplayAlerts 在使用 GetObject 打开工作簿时失败
- php - 电报 Laravel 机器人回复
- ios - 使用 ARGeoAnchor 显示 3D 模型
- microsoft-edge - 信息亭模式下的 Edge 失去焦点
- flutter - Dart - 如何检查字符串是否包含搜索输入中的每个单词?