将总列添加到跨选项卡透视查询

时间:2011-09-23 10:40:01

标签: sql sql-server sql-server-2005

如何在此查询中添加总列?

SELECT YearOfAccount, [Completed] AS Closed, [Open] AS Opened
FROM 
(SELECT YearOfAccount, Status, CaseCode
FROM Records ) myRecords 
PIVOT
(
COUNT(CaseCode)
FOR [Status] IN
( [Completed], [Open])
) AS pvt

目前我正在收回我想要的结果,但我希望在最右边包含所有已完成或打开的记录的总列。

1 个答案:

答案 0 :(得分:2)

添加

, [Completed] + [Open] AS Total

SELECT列表