SQL exercises on movie Database: Compute a report which contain the genres of those movies with their average time and number of movies for each genres
SQL movie Database: Join Exercise-10 with Solution
10. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of movies for each genres.
Sample table: movie
Sample table: genres
Sample table: movie_genres
Sample Solution:
SELECT gen_title, AVG(mov_time), COUNT(gen_title)
FROM movie
NATURAL JOIN movie_genres
NATURAL JOIN genres
GROUP BY gen_title;
Sample Output:
gen_title | avg | count ----------------------+----------------------+------- Adventure | 162.5000000000000000 | 2 Comedy | 93.0000000000000000 | 1 Drama | 134.2500000000000000 | 4 Horror | 100.0000000000000000 | 1 Thriller | 117.0000000000000000 | 1 Crime | 124.0000000000000000 | 2 Action | 137.0000000000000000 | 1 Music | 118.0000000000000000 | 1 War | 183.0000000000000000 | 1 Romance | 122.0000000000000000 | 1 Animation | 134.0000000000000000 | 1 Mystery | 137.3333333333333333 | 3 (12 rows)
Practice Online

Query Visualization:
Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1989, and sort the result set according to release date from highest date to lowest.
Next: Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his/her role in that production.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework