数据库
首页 > 数据库> > 【SQL】SQL中简单的行转列题解

【SQL】SQL中简单的行转列题解

作者:互联网

题目:
表:t_user

useridclassscore
1a90
1b80
1c70

编写SQL输出下列数据

useridabc
1908070

解题:

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