每月总和的总和

时间:2015-08-14 01:47:21

标签: sql sqlite

我的这个表有两列:

Price       Date
45.00       12/06/2015 12:32:54 AM
455.98      22/06/2015 11:00:32 AM
32.00       08/07/2015 09:11:45 AM
98.00       11/07/2015 19:22:32 PM

(日期格式为DD / MM / YYYY)

我需要得到按月分组的价格总和,为此我需要在sqlite中找到一个代码,该代码只截取该日期的某些部分(... 06 ...)(... 07 ...)。下面是我用于SELECT的某些部分的代码:

SELECT SUM(CAST(price as INTEGER)) as TOTALPERMONTH FROM cart_history GROUP BY ....... ORDER BY ID

我如何根据该行的某些部分进行分组?

2 个答案:

答案 0 :(得分:-1)

使用http://matplotlib.org/examples/widgets/slider_demo.html功能

select SUM(CAST(price as INTEGER)) as  Total, 
       strftime('%m', dateField) as Month
From yourtable
Group by strftime('%m', dateField)

答案 1 :(得分:-1)

使用HAVING子句。

SELECT SUM(CAST(price as INTEGER)) as TOTALPERMONTH 
FROM cart_history,Date
GROUP BY Date
HAVING Date IN('your dates ')'