SQL语句,获取查询RSQLite

SQL statement, get query RSQLite

我是 SQL 的新手,在使用 RSQLite 时遇到了问题。

这是我的 table 的示例:

counts    Month
0         June
4         June
2         March
5         July
3         July

我想使用 dbGetQuery 创建一个搜索查询,该查询将从我的 totals table 中统计每个月的计数。我正在寻找如下所示的输出:

counts    Month
4         June
2         March
8         July

到目前为止我有这个但不正确。 dbGetQuery(conn=db, "SELECT Count(counts) FROM totals group by [Month]")

从您想要的输出来看,您似乎不想计算 counts 而是求和。正如@AlexK 所述,您还需要 select 中的 Month 才能将其与总和结果一起显示

dbGetQuery(conn=db, "SELECT [Month], sum(counts) as counts FROM totals group by [Month]")