classid | order | name |
1 | 1 | a |
1 | 2 | b |
1 | 3 | c |
2 | 1 | d |
2 | 2 | e |
2 | 3 | f |
3 | 1 | g |
3 | 2 | h |
3 | 3 | i |
classid | name1 | name2 | name3 |
1 | a | b | c |
2 | d | e | f |
3 | g | h | i |
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