我有一张桌子
bagian lama
3 9
1 6
4 7
5 3
2 2
3 1
现在我想要这个
bagian(1) bagian(2) bagian(3) bagian(4) bagian(5)
6 2 1 7 3
SQL查询中正确的语法是什么
我已经试过了
select WHEN bagian = '1' THEN cuti_tahun.lama AS 1,WHEN bagian = '2' THEN cuti_tahun.lama AS 2,WHEN bagian = '3' THEN cuti_tahun.lama AS 3 from a
最佳答案
您可以使用条件聚合:
select min(case when bagian = 1 then lama end) as bagian_1,
min(case when bagian = 2 then lama end) as bagian_2,
min(case when bagian = 3 then lama end) as bagian_3,
min(case when bagian = 4 then lama end) as bagian_4,
min(case when bagian = 5 then lama end) as bagian_5
from cuti_tahun;
关于mysql - 显示数据库中具有2个条件的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28717766/