在单个记录上返回多行

时间:2010-08-30 14:13:16

标签: sql mysql

我需要检索此结果:

ROW1.id | ROW2.id | ROW3.id | ROW4.id
   1    |    2    |    3    |    4

从此结果开始select * from Table

id | value
1  | sample1
2  | sample2
3  | sample3
4  | sample4

任何想法?

感谢, 安德烈

2 个答案:

答案 0 :(得分:1)

尝试查看SQL的pivot

答案 1 :(得分:1)

你可以这样做:

select 
 (select id from table X where X.something = 123) as row1Id,
 (select id from table X where X.something = 456) as row2Id,
 (select id from table X where X.something = 789) as row3Id