Help in Reverse Pivot Query
I have no idea how i am going to do this. Simple example
studentid | sub1id | sub2id | and so on.....
------------------------------------开发者_JAVA百科----------------------
1 | 1 | 2 | and so on
3 | 5 | 6 | and so on
Using such table structure... I want a output in the following form a particular student
Student 1
student | sub |
======================
1 | 1 |
1 | 2 |
Student 2
student | sub |
======================
2 | 5 |
2 | 6 |
declare @T table
(
studentid int,
sub1id int,
sub2id int
)
insert into @T values
(1, 1, 2),
(3, 5, 6)
select studentid, sub
from (select studentid, sub1id, sub2id
from @T
where studentid = 3) as T
unpivot (sub for C in (sub1id, sub2id)) as U
精彩评论