SELECT movie_id, movie_title, movie_release_year, movie_genre, movie_plot, (SELECT AVG(sum_movie_rate) FROM (SELECT SUM(movie_rate) AS sum_movie_rate FROM user_movie_rate WHERE movie_id = ?) AS t1) AS average_rating FROM movie WHERE movie_id = ?
when I retrieve a specific information of a movie, I want to calculate the average ratings of the movie.
user_movie_rate looks like this
CREATE TABLE `user_movie_rate` (
`user_id` varchar(30) NOT NULL,
`movie_id` int(11) NOT NULL,
`movie_rate` int(11) DEFAULT NULL,
PRIMARY KEY (`user_id`,`movie_id`),
KEY `user_id` (`user_id`),
KEY `movie_id` (`movie_id`),
CONSTRAINT `movie_id` FOREIGN KEY (`movie_id`) REFERENCES `movie` (`movie_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`fbID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
the query above does not return average value of the rating for a specific movie.
What is the problem?