我正在尝试计算特定月份(例如一月份)销售量最大(书籍)的类别。我的payment_date列为日期时间格式。它说我的SQL语法有以下查询错误
SELECT category_id, SUM(payment_amount) AS Total FROM Payments GROUP BY category_id WHERE MONTH(payment_date) = 01 ORDER BY SUM(payment_amount) DESC LIMIT 1
答案 0 :(得分:0)
该语句的GROUP BY部分需要放在WHERE子句之后,因此您的查询应该是:
SELECT category_id, SUM(payment_amount) AS Total FROM Payments WHERE MONTH(payment_date) = 1 GROUP BY category_id ORDER BY SUM(payment_amount) DESC LIMIT 1