SELECT EXTRACT(YEAR_MONTH FROM import_date) AS import_month
, AVG(day_total) AS average_per_day
FROM (
SELECT import_date
, COUNT(`storage unit`) AS day_total
FROM sdon
GROUP BY import_date
) AS x
GROUP BY EXTRACT(YEAR_MONTH FROM import_date)
SELECT AVG(Pallets) AS AveragePallets,
DATE_FORMAT(import_date, '%b-%y') AS ImportMonth
FROM sdon
GROUP BY LEFT(import_date, 7)
ORDER BY LEFT(import_date, 7);
2条答案
按热度按时间8i9zcol21#
您可以按日期的年和月对原始查询的结果进行分组:
将
202207
这样的数字转换为2022-07
是很简单的。9w11ddsr2#
(我认为不需要子查询。)