方便的pivot
查詢出所要資料
select get_date as gd,id as cg, SUM(number) as sdn from table
group by get_date,id
想將id變為欄
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
留言
張貼留言