purchases(id,item,user,price,time);
时间字段是时间戳.
我需要一个每月返回一行的查询,该行将包含该月中每个项目的价格总和.
SELECT MONTH(`time`) AS month,SUM(price) AS price FROM your_table GROUP BY MONTH(`time`)
如果您有一年以上的数据,您可能还希望通过以下方式将年份包括在您的组中:
SELECT YEAR(`time`) AS year,MONTH(`time`) AS month,SUM(price) AS price FROM your_table GROUP BY YEAR(`time`),MONTH(`time`)