我有一個SQLite數據庫包含交易,他們每個人都有價格和transDate。SQLite按月份分組
我想檢索按月份分組的交易總和。檢索到的記錄應該是這樣的:
Price month
230 2
500 3
400 4
我有一個SQLite數據庫包含交易,他們每個人都有價格和transDate。SQLite按月份分組
我想檢索按月份分組的交易總和。檢索到的記錄應該是這樣的:
Price month
230 2
500 3
400 4
這是一件好事,而你組每月應檢查今年還
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);
您可以在本月啓動組:
select date(DateColumn, 'start of month')
, sum(TransactionValueColumn)
from YourTable
group by
date(DateColumn, 'start of month')
嘗試以下操作:
SELECT SUM(price), strftime('%m', transDate) as month
FROM your_table
GROUP BY strftime('%m', transDate);
使用corresponding page SQLite的文檔中爲將來的參考。
SELECT
SUM(Price) as Price, strftime('%m', myDateCol) as Month
FROM
myTable
GROUP BY
strftime('%m', myDateCol)
工程,但可能將2009年3月與2010年3月3個月 – Andomar 2010-05-24 09:27:23
哪些表中的列? – Mark 2010-05-24 09:16:12