Skip to content
Advertisement

MAX on columns generated by SUM and GROUP BY

I’m trying to get the MAX on a column which is generated dynamically using the SUM statement. The SUM statement is used together with the ‘GROUP by’ syntax.

This is the original query, however it needs to be modified to work with grouping, sums and of course MAX.

As you can see SUM is adding all the values inside video_plays as total_video_plays..

But I SIMPLY want to get the MAX of total_video_plays

My attempts are below, however they do not work..

How would you get the MAX on a column made dynamically without using subqueries – Because the above is already placed within one.

Advertisement

Answer

Something like

Hat Tip OMG Ponies for proper MySQL dialect.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement