行转列:
name | course | grade |
zhangsan | java | 20 |
zhangsan | c# | 60 |
zhangsan | python | 40 |
lisi | java | 109 |
lisi | c# | 30 |
lisi | python | 20 |
wangwu | java | 33 |
select name ,
sum(case when course = 'java' then grade end) as 'java',
sum(case when course = 'c#' then grade end) as 'c#',
sum(case when course = 'python' then grade end) as 'python'
from ccc GROUP BY name;
name | java | c# | python |
zhangsan | 20 | 60 | 40 |
lisi | 109 | 30 | 20 |
wangwu | 33 |