0

I'm trying to get the lowest average rating for Movies in a database.

Currently I have:

select movie.movietitle as "Lowest Average Rating"
from movie, rating 
where movie.movieid = rating.movieid
group by movie.movietitle
having avg(rating.rating) = min(avg(rating.rating));

But I'm getting the error "group function is nested too deeply." Can anyone provide me with a correct way of doing this and explain why this doesn't work?

Thanks

1 Answer 1

1
SELECT MOVIETITLE AS "Movie Title", AVG(RATING) AS "Lowest Average Rating"
FROM MOVIE, RATING
WHERE MOVIE.MOVIEID = RATING.MOVIEID
GROUP BY MOVIETITLE
HAVING AVG(RATING) =
(
    SELECT MIN(AVG(RATING)) AS "AVGRating"
    FROM MOVIE, RATING
    WHERE MOVIE.MOVIEID = RATING.MOVIEID
    GROUP BY MOVIETITLE
)
Sign up to request clarification or add additional context in comments.

3 Comments

Oh sorry, I think I should rephrase. I meant "Find the movie title of the movie with the lowest average rating."
@Sam have you seen the results on sqlfiddle?
Hmm, yes I see that. For some reason, when I run it against my data I get many results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.