Sum over values by month in milliseconds

亡梦爱人 提交于 2020-01-24 14:32:33

问题


I have table with Values and Date. Values in Integer and date is Integer in milliseconds from 1970's... I need to get sum(value) for each month and i haven't any idea how to do it with date in milliseconds. Is it possible? Thanks.

My table "entry"

amount    |   date    
----------------------------
300       |   1390075200000
150       |   1390132500000
20        |   1391075200000
...       |   .............

What i want to get:

01.2014  |  450
02.2014  |  20
....

回答1:


You have to convert the dates into a format supported by SQLite so that you can extract the month:

SELECT strftime('%Y-%m', date / 1000, 'unixepoch') AS month,
       SUM(value) AS sum
FROM entry
GROUP BY 1


来源:https://stackoverflow.com/questions/23220501/sum-over-values-by-month-in-milliseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!