SQL_行转列

SQL命令

SQL进行数据展示的时候,常常会用到行转列,思路很重要
使用union all ,没有的字段用0表示,然后max
select t1.id,  max(data)as data,max(test_dat ) as test_dat
from(
select id, 0 as data,test_dat from a
union all
select id, data,0 as test_dat  from b)t1
group by t1.id

使用case when
posted @ 2022-06-28 15:21  辰令  阅读(197)  评论(0编辑  收藏  举报