无法在日期为 milliseconddd 的 sqlite 中按年月分组

Not able to group by year-month in sqlite with date as milliseconddd

我的 sqlite table 中的日期列值以毫秒为单位。现在 - 我需要按月、年分组。例如,对于 2020 年一月,sum = 1200,对于 2020 年二月,sum = 1500 等

我检查了几个现有的 SO 建议,但 strftime 对我不起作用。 (可能是因为我将日期存储为毫秒而不是 SQLITE 文档建议的其他标准格式。

我尝试了以下代码,但 returns 只有一行对我来说。

select SUM(amount) as amount, 
strftime("%m-%Y", date) as 'month-year' 
from sys_item group by strftime("%m-%Y", date);

有人可以帮忙吗?

这是示例数据

我期望两列结果如下:

2020-08 SUM1 2020-07 SUM2

将您的日期除以 1000 以去除毫秒并将其转换为日期:

select strftime('%Y-%m', date/1000, 'unixepoch') [year-month],
       sum(amount) amount  
from sys_item 
group by [year-month];