数据如下,表名 AAA
classidordername
11a
12b
13c
21d
22e
23f
31g
32h
33i
期望结果如下
classidname1name2name3
1abc
2def
3ghi

sql如下:


select classid,
max(case when orderid =1 then name else '' end ) as name 1 ,
max(case when orderid =2 then name else '' end ) as name 2,
max(case when orderid =3 then name else '' end ) as name 3
from AAA group by classid

10-26 06:39