本文介绍了如何在sql server 2008中使用数据透视表查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
im use pivot table query for display the data...
in the Abc table 4 columns like SID (auto increment), StudentID, Attendance, Day.
select * from Abc
pivot (max (Attendance) for Day in ([Day1],[Day2],[Day3])) as DayWise
Output :-
SID StudentID Day1 Day2 Day3
----------------------------------------
1 101 A null null
2 101 null A null
3 101 null null A
4 102 A null null
5 103 null A null
But i want this type of output :-
StudentID Day1 Day2 Day3
---------------------------------
101 A A A
102 A A null
So how can i do this....
Thanx in advance...
推荐答案
select distinct studentid,
(select attendance from abc where day='Day1' and abc.studentid=t1.studentid) day1,
(select attendance from abc where day='Day2' and abc.studentid=t1.studentid) day2,
(select attendance from abc where day='Day3' and abc.studentid=t1.studentid) day3
from abc t1
这篇关于如何在sql server 2008中使用数据透视表查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!