質問

I have a table like this:

id name 
1  a    
2  b    
3  c    
4  d   
5  e    

If I do select name from tableTest where id = 1 or id = 2, I got this:

name
a
b

But I want a result like this:

name_1   name_2 
a        b

-- 1, 2: Best: the value of id, or (AA, BB..) or (a, b, c,..) or anything

How can I do that

役に立ちましたか?

解決

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

SQL Fiddle Demo

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top