题目:
表:t_user
userid | class | score |
---|---|---|
1 | a | 90 |
1 | b | 80 |
1 | c | 70 |
编写SQL输出下列数据
userid | a | b | c |
---|---|---|---|
1 | 90 | 80 | 70 |
解题:
select
userid,
max(case when class = 'a' then score end) as a,
max(case when class = 'b' then score end) as b,
max(case when class = 'c' then score end) as c
from t_user
group by userid