给定表:
ID NAME VALUE
1 A N
1 B Y
1 C N
我希望表格采用以下格式:
ID A B C
1 N Y N
答案 0 :(得分:3)
您可以使用条件聚合
select id,
max(case when name='A' then value end) as A,
max(case when name='B' then value end) as B,
max(case when name='C' then value end) as C
from tablename
group by id