就是如果我们要求这种情况
uid course socre
1 Chinese 90
1 Math 90
2 Chinese 100
2 Math 110
通过sql查询成这样
uid ChineseSocre MthScore
1 90 90
2 100 100
使用case when !
select sid ,max (case when subject = '语文' then score else 0 end) `语文` from score group by sid;
就是如此简单。
为什么要使用max呢?
其实想过滤掉0这个值的