我有一个SQLite数据库,其中包含交易,每个交易都有一个 价格 和一个 transDate 。
我想检索按月分组的交易总和。检索到的记录应类似于以下内容:
Price month 230 2 500 3 400 4
当您按MONTH分组时总是很好,还应该检查YEAR
select SUM(transaction) as Price, DATE_FORMAT(transDate, "%m-%Y") as 'month-year' from transaction group by DATE_FORMAT(transDate, "%m-%Y");
对于SQLITE
select SUM(transaction) as Price, strftime("%m-%Y", transDate) as 'month-year' from transaction group by strftime("%m-%Y", transDate);