I have this code and it gives me sold seats summarized for each movie:
SELECT mName, SUM(soldSeats)
FROM movie, show, prog
WHERE movie.movieID = prog.movieID
AND prog.showID = show.showID
GROUP BY mName
The problem is to find movie that have the max of seats sold, I have tried to add this, but only get no rows:
HAVING SUM(soldseats) = (SELECT MAX(SUM(soldseats)) FROM show
GROUP BY solgteplasser)
Do anyone have a suggestion? Here is how the tables looks: Sum of a activity
This way you order your selection descending by your SUM
and you select the first row only using Rownum
which is the row with the highest SUm.
EDIT:
Also in case you got Nulls in your SUM column make sure you add a NULLS LAST after your ORder By like this: