如何找出一个月内最常用的畅销书类别

mhd8tkvw  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(285)

我试图计算一个特定月份(比如说一月份)销量最高的图书类别。我的付款日期列是日期时间格式。它说我的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
y53ybaqx

y53ybaqx1#

语句的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

相关问题