所以我有一堆数据,我已经将它按列名和月份分组。这是我到目前为止的 SQL 查询
TestName 是列名,POE 业务规则/提交每列出现多次 VExecutionGlobalHistory 是表的名称,我使用 Microsoft SQL Server Management Studio 2010
select
year(dateadd(mm,datediff(mm,0,StartTime),0)),
datename(month,dateadd(mm,datediff(mm,0,StartTime),0)),TestName,
Case WHEN Testname = 'POE Business Rules' THEN (count(TestName)*36) WHEN TestName = 'Submit' THEN (count(TestName)*6) ELSE 0 END
From VExecutionGlobalHistory
group by
year(dateadd(mm,datediff(mm,0,StartTime),0)),
datename(month,dateadd(mm,datediff(mm,0,StartTime),0)),TestName
这个查询给了我这种格式
2013 |APRIL| POE Business Rules| 1044
2013 |APRIL| SUBMIT | 96
2013 |JULY | POE Business Rules| 216
2013 |JULY | SUBMIT | 102
我想要一个最终格式,它只有每个月的计数总和
2013|APRIL|SUM of the counts or (1044 + 96)
2013|JULY |SUM of the counts or (216 + 102)
我不需要 testname 只是每月计数的总和
我曾尝试在案例之前添加 SUM,但出现
"Cannot perform an aggregate function on an expression containing an aggregate or a subquery."
错误。
关于另一种方法的任何建议?