我有一张这样的表:
id name
1 a
2 b
3 c
4 d
5 e
如果我select name from tableTest where id = 1 or id = 2
,我得到了这个:
name
a
b
但我想要一个这样的结果:
name_1 name_2
a b
-- 1, 2: Best: the value of id, or (AA, BB..) or (a, b, c,..) or anything
我该怎么做
答案 0 :(得分:0)
select max(case when id=1 then name end) as name_1,
max(case when id=2 then name end) as name_2
From test