且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据条件替换null

更新时间:2023-02-07 14:06:38

这看起来像左连接和条件逻辑:

This looks like a left join and conditional logic:

select 
    t.id,
    coalesce(t.col1, t1.col1) col1,
    coalesce(t.col2, t1.col2) col2,
    coalesce(t.col3, t1.col3) col3,
    t.source_id
from mytable t
left join mytable t1 on t1.id = t.source_id