需要帮助在表格下方转移/取消转移,例如SQL Server 2005的结果。
ID,Type,TypeValue
1,A,10
1,A,11
1,A,12
1,B,2
1,B,3
1,C,30
1,C,31
结果集:
ID,A,B,C
1,10,2,30
1,10,2,31
1,11,2,30
1,11,2,31
1,12,2,30
1,12,2,31
1,10,3,30
1,10,3,31
1,11,3,30
1,11,3,31
1,12,3,30
1,12,3,31
答案 0 :(得分:1)
尝试此查询
Select A.ID, A.TYPEVALUE, B.TYPEVALUE, C.TYPEVALUE
From (Select * From pivot_task Where TYPE = 'A') As A
Left Join (Select * From pivot_task Where TYPE = 'B') As B on 1=1
Left Join (Select * From pivot_task Where TYPE = 'C') As C On 1=1
Order BY B.TYPEVALUE, A.TYPEVALUE, C.TYPEVALUE
和这样的出局。
ID TYPEVALUE TYPEVALUE TYPEVALUE
----------- --------- --------- ---------
1 10 2 30
1 10 2 31
1 11 2 30
1 11 2 31
1 12 2 30
1 12 2 31
1 10 3 30
1 10 3 31
1 11 3 30
1 11 3 31
1 12 3 30
1 12 3 31