方便的pivot

查詢出所要資料
select get_date as gd,id as cg, SUM(number) as sdn  from table 
group by  get_date,id


想將id變為欄

 select  gd,ISNULL([NRDA1],0) as NRDA1 ,  ISNULL([NRDA6],0) as NRDA6 ,  ISNULL([NRDS3],0) as NRDS3
from  (
select get_date as gd,id as cg, SUM(number) as sdn  from table
group by  get_date,id
) as gtable pivot
( sum(sdn) for cg in (  NRDA1 ,  NRDA6 ,  NRDS3   ) ) as ptable

http://technet.microsoft.com/zh-tw/library/ms177410(v=sql.105).aspx

留言

這個網誌中的熱門文章

SQL SEVER備份與還原遭遇問題

asp.net頁面間傳值