Not Boring Movies - Problem
๐ฌ Cinema Database Query Challenge
You're working as a data analyst for a movie streaming platform! The cinema database contains information about various movies including their ID, title, genre description, and rating.
Your task is to help users discover interesting movies by filtering out the boring ones. Specifically, you need to:
- Find movies with odd-numbered IDs (1, 3, 5, 7, etc.)
- Exclude movies where the description is exactly
"boring" - Return results ordered by rating in descending order (highest rated first)
Goal: Write a SQL query that returns the filtered movie list to help users find the most interesting, highly-rated films!
Input & Output
example_1.sql โ Basic Filtering
$
Input:
Cinema table:
+----+----------+-------------+--------+
| id | movie | description | rating |
+----+----------+-------------+--------+
| 1 | War | great 3D | 8.9 |
| 2 | Science | fiction | 8.5 |
| 3 | irish | boring | 6.2 |
| 4 | Ice song | Fantacy | 8.6 |
| 5 | House card| Interesting| 9.1 |
+----+----------+-------------+--------+
โบ
Output:
+----+------------+-------------+--------+
| id | movie | description | rating |
+----+------------+-------------+--------+
| 5 | House card | Interesting | 9.1 |
| 1 | War | great 3D | 8.9 |
+----+------------+-------------+--------+
๐ก Note:
Movies with odd IDs (1, 3, 5) are candidates. Movie ID 3 is excluded because description is 'boring'. Remaining movies (1, 5) are sorted by rating DESC: 9.1, then 8.9.
example_2.sql โ All Movies Boring
$
Input:
Cinema table:
+----+----------+-------------+--------+
| id | movie | description | rating |
+----+----------+-------------+--------+
| 1 | Action | boring | 7.0 |
| 3 | Comedy | boring | 8.0 |
| 5 | Drama | boring | 9.0 |
+----+----------+-------------+--------+
โบ
Output:
Empty result set
+----+-------+-------------+--------+
| id | movie | description | rating |
+----+-------+-------------+--------+
+----+-------+-------------+--------+
๐ก Note:
All movies with odd IDs have 'boring' descriptions, so they are all filtered out, resulting in an empty result set.
example_3.sql โ Single Movie Result
$
Input:
Cinema table:
+----+----------+-------------+--------+
| id | movie | description | rating |
+----+----------+-------------+--------+
| 1 | Avengers | superhero | 9.5 |
| 2 | Titanic | romance | 8.8 |
+----+----------+-------------+--------+
โบ
Output:
+----+----------+-------------+--------+
| id | movie | description | rating |
+----+----------+-------------+--------+
| 1 | Avengers | superhero | 9.5 |
+----+----------+-------------+--------+
๐ก Note:
Only movie with ID 1 has an odd ID. It's not boring, so it's included in the result. ID 2 is even, so excluded.
Visualization
Tap to expand
Understanding the Visualization
1
Scan All Movies
Database engine examines each movie record in the Cinema table
2
Check ID Parity
For each movie, calculate ID % 2 to determine if it's odd (remainder = 1)
3
Check Description
Verify that the description field is not exactly equal to 'boring'
4
Collect Matches
Gather all movies that pass both filter conditions
5
Sort by Rating
Arrange the filtered results in descending order by rating (highest first)
Key Takeaway
๐ฏ Key Insight: SQL databases excel at filtering and sorting operations. Use WHERE clauses for filtering conditions and ORDER BY for sorting - let the database engine optimize the execution plan for you!
Time & Space Complexity
Time Complexity
O(n)
Linear scan through all records to apply filters, plus O(m log m) for sorting filtered results where m is the number of matching records
โ Linear Growth
Space Complexity
O(1)
Database query uses constant additional space for filtering operations
โ Linear Space
Constraints
- 1 โค id โค 104
- 1 โค movie.length โค 100
- 1 โค description.length โค 100
- 0.0 โค rating โค 10.0 (with exactly 2 decimal places)
- All movie names and descriptions contain only printable ASCII characters
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code