首页 > 解决方案 > 使用复合 sql 语句

问题描述

我正在使用https://try.askgit.com/获取有关回购的统计信息。现在我需要获取上个月(6/21)的提交数量,我将如何使用 sum 函数来做到这一点?

我有这个语句,它查询每个作者当月的提交次数,然后我只对 count 列求和,但我不确定如何在 SQL 中执行此操作:

SELECT author_name, count(*)
FROM commits 
WHERE '2021-06-01T00:00:00.000' <= author_when AND author_when <= '2021-06-30T00:00:00.000' 
GROUP BY author_name
ORDER BY count(*) DESC

标签: sql

解决方案


假设您不想按作者计数,您可以这样做:

SELECT count(*) as Count
FROM commits 
WHERE '2021-06-01T00:00:00.000' <= author_when AND author_when < '2021-07-01T00:00:00.000' 

推荐阅读