我是编码和SQL方面的新手。我有这样的数据库:
ID| technique
--|----------
1 | 1
1 | 2
1 | 3
2 | 1
2 | 3
3 | 1我需要这个结果
ID| technique1|technique2|technique3
--|-----------|----------|----------
1 | 1 | 2 | 3
2 | 1 |. | 3
3 | 1 |. |.有可能吗?
发布于 2017-04-08 21:27:19
您可以使用条件聚合来完成这一任务:
select id,
max(case when technique = 1 then 1 end) as technique1,
max(case when technique = 2 then 2 end) as technique2,
max(case when technique = 3 then 3 end) as technique3
from t
group by id;我把.解释为NULL。
https://stackoverflow.com/questions/43300464
复制相似问题