集团通过一个月的SQLite [英] Group by month in SQLite
本文介绍了集团通过一个月的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含交易,他们每个人有一个SQLite数据库中的价格的和的 transDate 的
我想检索分组一个月交易的总和。在检索的记录应该是这样的:
价格每月
230 2
500 3
400 4
解决方案
这是一件好事,而你每月组应该检查一年也就
SELECT SUM(交易)价格,
DATE_FORMAT (transDate,M-%%Y)作为月 - 年从交易团
。通过DATE_FORMAT(transDate,M-%%Y);
SQLite的
SELECT SUM(交易)价格,
的strftime(%M-%Y,transDate)为月 - 年从交易团
。通过的strftime(%M-% Y,transDate);
I have an SQLite database which contains transactions, each of them having a price and a transDate.
I want to retrieve the sum of the transactions grouped by month. The retrieved records should be like the following:
Price month
230 2
500 3
400 4
解决方案
it is always good while you group by MONTH it should check YEAR also
select SUM(transaction) as Price,
DATE_FORMAT(transDate, "%m-%Y") as 'month-year'
from transaction group by DATE_FORMAT(transDate, "%m-%Y");
FOR SQLITE
select SUM(transaction) as Price,
strftime("%m-%Y", transDate) as 'month-year'
from transaction group by strftime("%m-%Y", transDate);
这篇关于集团通过一个月的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文