来源如下:
NAME |SEX
-----+----
A |MALE
B |FEMALE
C |MALE
D |FEMALE
E |MALE
必需的输出,将第二列中的值作为标题旋转,如下所示:
MALE FEMALE
A B
C D
E
答案 0 :(得分:0)
对于Oracle:
select * from (
select * from [table name]
)src
pivot
(max(name) for sex in ('Male' as MALE,'Female' as FEMALE))pvt
对于SQL Server:
select * from (
select * from [table name]
)src
pivot
(max(name) for sex in ([Male],[Female]))pvt