-1

我有以下 mysql 表

amount  timestamp
3       1367638029
4       1367638029
5       1366445119
8       1366445200

我如何根据本月(不是过去 30 天)和上个月返回总和(金额),如下所示

            total amount
This month  7
Last month  13
4

1 回答 1

1

这可以通过以下方式完成:

SELECT SUM(AMOUNT)
FROM yourtable
WHERE MONTH(FROM_UNIXTIME(timestamp)) IN/BETWEEN ... -- consider YEAR(...)as well
GROUP BY MONTH(FROM_UNIXTIME(timestamp))
于 2013-05-04T08:26:09.783 回答