我有以下mysql表
amount timestamp
3 1367638029
4 1367638029
5 1366445119
8 1366445200
如何根据本月(不是过去30天)以及上个月(如下所示)返回金额(金额)
total amount
This month 7
Last month 13
答案 0 :(得分:1)
这可以这样做:
SELECT SUM(AMOUNT)
FROM yourtable
WHERE MONTH(FROM_UNIXTIME(timestamp)) IN/BETWEEN ... -- consider YEAR(...)as well
GROUP BY MONTH(FROM_UNIXTIME(timestamp))