7 kyu

Filtering Films by Special Features in PostgreSQL: Part 1

Description:

Write a PostgreSQL query that selects film_id, the title and special_features columns from the film table in the DVD rental database, and returns only the films that have both "Trailers" and "Deleted Scenes" as their special feature. special_features is the text[] type. It represents a one-dimensional array of values, where each value is of the text data type.

Notes:
  • for the sample tests, static dump of DVD Rental Sample Database is used, for the final solution - random tests.
  • Note that this query should return films that have other special features in addition to "Trailers" and "Deleted Scenes".
  • The result should be order by title alphabetically, if title is the same - then by film_id in asc order.

Schema:

film table:

Column            | Type      | Modifiers
------------------+-----------+-----------
film_id           | integer   | not null
title             | varchar   | not null
description       | text      | not null
release_year      | integer   | not null
language_id       | integer   | not null 
rental_duration   | integer   | not null
rental_rate       | numeric   | not null
length            | integer   | not null
replacement_cost  | numeric   | not null
rating            | varchar   | not null
last_update       | timestamp | not null
special_features  | text[]    | not null

Desired Output

The desired output should look like this:

film_id | title                             | special_features                       |
--------+-----------------------------------+----------------------------------------|
   32   | A Shawshank Redemption            | {Trailers, Deleted Scenes}             | 
   14   | Monty Python and the Holy Grail   | {Deleted Scenes,Commentaries,Trailers} |
...
Databases
SQL

Stats:

CreatedMay 4, 2023
PublishedMay 4, 2023
Warriors Trained869
Total Skips84
Total Code Submissions1958
Total Times Completed559
SQL Completions559
Total Stars8
% of votes with a positive feedback rating95% of 68
Total "Very Satisfied" Votes61
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes0
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad