按月份以毫秒为单位求和值 [英] Sum over values by month in milliseconds

查看:225
本文介绍了按月份以毫秒为单位求和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有价值观和日期表。在值整数和日期整数毫秒从1970年的...
我需要每个月总和(价值),我没有任何想法如何带日期以毫秒为单位做。可能吗?
谢谢你。

我的表项

 量|日期
----------------------------
300 | 1390075200000
150 | 1390132500000
20 | 1391075200000
... | .............

我想:

  01.2014 | 450
02.2014 | 20
....


解决方案

您必须转换日期为由SQLite的支持这样就可以提取一个月的格式:

  SELECT的strftime(%Y-%M',日期/ 1000,'unixepoch')为月,
       SUM(值)为SUM
从入门
GROUP BY 1

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
....

解决方案

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

这篇关于按月份以毫秒为单位求和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆