我想在mysql中从当年其他月份获取销售额最大的三个月的数据
我试过这个问题我想在mysql中从当年其他月份获取销售额最大的三个月的数据,mysql,Mysql,我试过这个问题 select id, year(created_at) as year,month(created_at) as month,sum(grandtotal) as monthtotalsale from bookings WHERE YEAR(created_at)=YEAR(CURRENT_DATE) group by month(created_at) order by id, year(created_at),month(created_at) 但是这个查询返回每个月
select id, year(created_at) as year,month(created_at) as month,sum(grandtotal) as monthtotalsale
from bookings
WHERE YEAR(created_at)=YEAR(CURRENT_DATE) group by month(created_at)
order by id, year(created_at),month(created_at)
但是这个查询返回每个月的总销售额
这将为您提供今年月销售量最高的三个月
SELECT
id,
YEAR(created_at) AS year,
MONTH(created_at) AS month,
SUM(grandtotal) AS monthtotalsale
FROM
bookings
WHERE
YEAR(created_at) = YEAR(CURRENT_DATE)
GROUP BY MONTH(created_at)
ORDER BY monthtotalsale DESC
LIMIT 3