转换前的 :ID name sex num1 tom 男 22 tom 男 33 tom 男 44 tom 男 5这是转换后的结果 ID name sex num1 num2 num3 num41 tom 男 2 3 4 5
select MIN(id) as ID, name, sex, sum(case when num=2 then 2 end) as num2,sum(case when num=3 then 3 end) as num3,sum(case when num=4 then 4 end) as num4,sum(case when num=5 then 5 end) as num5from 表名 group by name,sex
时间: 2024-12-19 22:51:03