【SQL】SQL中简单的行转列题解
作者:互联网
题目:
表: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
标签:case,end,题解,SQL,when,转列,score,max,class 来源: https://blog.csdn.net/qq_40180229/article/details/121841056