I need a little help with an SQL exercise I'm doing, basically I have a small SQL database of movies, their ratings, the year they come out etc... and I have to add 25 years to any movie with an average rating of 4 or higher.
The names are quite straight forward, with mID being the movie ID and everything else is easily readable, but if needed I can copy the actual database (its tiny).
What i've wrote is:
update Movie
set year=year+25
where mID in
(select mID from Rating,
(select avg(stars) as avgstars
from Rating
group by mID)
where avgstars>=4)
but I can't work out how I'm doing the avg wrong, as I need to get the average for movies of the same mID (which is why I grouped by mID), but the result of running this adds 25 years to several more movies than it should, suggesting too many mIDs satisfy the condition avgstars>=4. so I must have done the avg command wrong.
The little web application that checks my results automatically performs a select * from Movie after any commands I enter, so I can't just do a step by step look at what I wrote and look at the results, as it always will just show me the entire movie table.
Any help on where I went wrong working out the average would be great
The names are quite straight forward, with mID being the movie ID and everything else is easily readable, but if needed I can copy the actual database (its tiny).
What i've wrote is:
update Movie
set year=year+25
where mID in
(select mID from Rating,
(select avg(stars) as avgstars
from Rating
group by mID)
where avgstars>=4)
but I can't work out how I'm doing the avg wrong, as I need to get the average for movies of the same mID (which is why I grouped by mID), but the result of running this adds 25 years to several more movies than it should, suggesting too many mIDs satisfy the condition avgstars>=4. so I must have done the avg command wrong.
The little web application that checks my results automatically performs a select * from Movie after any commands I enter, so I can't just do a step by step look at what I wrote and look at the results, as it always will just show me the entire movie table.
Any help on where I went wrong working out the average would be great
Last edited: