我是SQL新手,遇到RSQLite问题。
以下是我的表格示例:
counts Month
0 June
4 June
2 March
5 July
3 July
我想使用dbGetQuery创建一个搜索查询,它将从我的totals
表中计算每个月的计数。我正在寻找看起来像这样的输出:
counts Month
4 June
2 March
8 July
到目前为止,我有这个但是不正确。 dbGetQuery(conn=db, "SELECT Count(counts) FROM totals group by [Month]")
答案 0 :(得分:1)
从您想要的输出看来,您似乎不想计算counts
,而是将它们相加。正如@AlexK所述,您在选择中还需要Month
才能将其与总和结果一起显示
dbGetQuery(conn=db, "SELECT [Month], sum(counts) as counts FROM totals group by [Month]")