sql横表变竖表

表1 表2sql 如何表1 变表2 数据量很大
2025-03-10 11:16:11
推荐回答(1个)
回答1:

select xm,gh,
max(case when date=1 then money else null end) as D1,
max(case when date=2 then money else null end) as D2,
max(case when date=3 then money else null end) as D3
from tablename
group by xm,gh

如果max显示不对的话换成min