SELECT Year_, Month_, SUM(Counts)
FROM (
SELECT YEAR(DATEADD(MM,DATEDIFF(MM,0,StartTime),0))'Year_'
,DATENAME(MONTH,DATEADD(MM,DATEDIFF(MM,0,StartTime),0))'Month_'
,TestName
,CASE WHEN Testname = 'POE Business Rules' THEN (count(TestName)*36)
WHEN TestName = 'Submit' THEN (COUNT(TestName)*6)
ELSE 0
END 'Counts'
FROM VExecutionGlobalHistory
GROUP BY YEAR(DATEADD(MM,DATEDIFF(MM,0,StartTime),0))
,DATENAME(MONTH,DATEADD(MM,DATEDIFF(MM,0,StartTime),0))
,TestName
)sub
GROUP BY Year_, Month_
ORDER BY CAST(CAST(Year_ AS CHAR(4)) + Month_ + '01' AS DATETIME)
2条答案
按热度按时间wko9yo5t1#
Dplyr summarize across everything
方法:base::xtabs()
方法,需要命名所有数据行:感谢@akrun https://stackoverflow.com/a/74619313/10276092的替代方案
eit6fx6z2#
在
SQL
中,您可以使用子查询:更新:添加了
ORDER BY
,以按年份/月份排序,最早的排在最前面。