w3resource
SQL exercises

SQL exercises on movie Database: Compute a report which shows the year when most of the Mystery movies produces, and number of such movies and their average rating

SQL movie Database: Join Exercise-23 with Solution

23. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.

Sample table: movie


Sample table: genres


Sample table: movie_genres


Sample table: rating


Sample Solution:

SELECT mov_year,gen_title,count(gen_title), avg(rev_stars)
FROM movie 
NATURAL JOIN movie_genres 
NATURAL JOIN genres
NATURAL JOIN rating
WHERE gen_title='Mystery' 
GROUP BY mov_year,gen_title;

Sample Output:

 mov_year |      gen_title       | count |        avg
----------+----------------------+-------+--------------------
     1958 | Mystery              |     1 | 8.4000000000000000
(1 row)

Practice Online


Movie database model

Query Visualization:

Duration:

Query visualization of Compute a report which shows the year when most of the Mystery movies produces, and number of such movies and their average rating - Duration

Rows:

Query visualization of Compute a report which shows the year when most of the Mystery movies produces, and number of such movies and their average rating - Rows

Cost:

Query visualization of Compute a report which shows the year when most of the Mystery movies produces, and number of such movies and their average rating - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.
Next: Write a query in SQL to generate a report which contain the columns movie title, name of the female actor, year of the movie, role, movie genres, the director, date of release, and rating of that movie.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming