select
coalesce(a.id,b.id,c.id) as id
,coalesce(a.num,0)
,coalesce(b.num,0)
,coalesce(c.num,0)
from table1 a
full join table2 b
on a.id=b.id
full join table3 c
on coalesce(a.id,b.id)=c.id

该SQL查询使用COALESCE函数处理NULL值,通过fulljoin将table1、table2和table3三张表联接在一起,基于id字段进行匹配。查询结果包括a、b、c三表的id和num字段,若某字段为空则填充0。
select
coalesce(a.id,b.id,c.id) as id
,coalesce(a.num,0)
,coalesce(b.num,0)
,coalesce(c.num,0)
from table1 a
full join table2 b
on a.id=b.id
full join table3 c
on coalesce(a.id,b.id)=c.id

9081
4527
1万+
634

被折叠的 条评论
为什么被折叠?