【发布时间】:2015-03-19 16:50:12
【问题描述】:
电流输出
WeekNumber WeeklyCount
11 100
10 200
9 300
8 400
7 500
期望的输出
WeekNumber 11 10 9 8 7
WeeklyCount 100 200 300 400 500
当前查询:
SELECT Top 5 DatePart(ww, DATE) as weekNumber, Count(id) as WeeklyCount
FROM dbo.AL
Where DatePart(ww, DATE) <> DatePart(ww, GetDate())
group by DatePart(ww, DATE)
order by DatePart(ww, DATE) desc
如何使用 pivot 函数返回所需的输出?
Pivot function query
【问题讨论】:
-
如果你知道pivot为什么不试试呢?网上有很多例子
-
我尝试了很多次都没有成功,我假设 pivot 是答案......
标签: sql sql-server sql-server-2008 date pivot