Here's what I'm trying to achieve. Basically I have a relation in which I have a count for each ID and month. I'd like to sum the counts for each id by month (middle table in the picture) and then from that find the maximum value from all those sums by month, and show the month, id, and the maximum value in that order. Here's what I've got so far:
SELECT month, MAX(summed_counts) AS maximum_result
FROM
(SELECT month, id, SUM(counts) AS summed_counts
FROM info WHERE year=2017 GROUP BY month, id)
AS final_result GROUP BY month ORDER BY month ASC;
However as soon as I add id
it no longer works:
SELECT month, id, MAX(summed_counts) AS maximum_result
FROM
(SELECT month, id, SUM(counts) AS summed_counts
FROM info WHERE year=2017 GROUP BY month, id)
AS final_result GROUP BY month, id ORDER BY month ASC;
Any suggestions?