Forem

Abinaya Dhanraj
Abinaya Dhanraj

Posted on

task -002

  1. Movies where special_features is NULL

SELECT *
FROM film
WHERE special_features IS NULL;

Explanation:
Here I am checking for NULL values.
We cannot use = for NULL, so I used IS NULL.

  1. Rental duration more than 7 days

SELECT *
FROM film
WHERE rental_duration > 7;

Explanation:
Filtered movies where rental duration is greater than 7.

  1. Rental rate = 4.99 and replacement cost > 20

SELECT *
FROM film
WHERE rental_rate = 4.99
AND replacement_cost > 20;

Explanation:
Used AND because both conditions must be true.

  1. Rental rate = 0.99 OR rating = 'PG-13'

SELECT *
FROM film
WHERE rental_rate = 0.99
OR rating = 'PG-13';

Explanation:
Used OR because any one condition is enough.

  1. First 5 movies sorted by title

SELECT *
FROM film
ORDER BY title
LIMIT 5;

Explanation:
Sorted by title and took first 5 rows.

  1. Skip 10 rows, next 3 highest replacement cost

SELECT *
FROM film
ORDER BY replacement_cost DESC
OFFSET 10
LIMIT 3;

Explanation:
Sorted by highest cost, skipped first 10, then took next 3.

  1. Rating is G, PG, or PG-13

SELECT *
FROM film
WHERE rating IN ('G', 'PG', 'PG-13');

Explanation:
Used IN instead of multiple OR conditions.

  1. Rental rate between 2 and 4

SELECT *
FROM film
WHERE rental_rate BETWEEN 2 AND 4;

Explanation:
Used BETWEEN for range values.

  1. Titles start with 'The'

SELECT *
FROM film
WHERE title LIKE 'The%';

Explanation:
% means anything after "The".

  1. First 10 movies with multiple conditions

SELECT *
FROM film
WHERE rental_rate IN (2.99, 4.99)
AND rating = 'R'
AND title LIKE '%Love%'
LIMIT 10;

Explanation:
Combined multiple filters and limited result.

  1. Titles containing %

SELECT *
FROM film
WHERE title LIKE '%\%%' ESCAPE '\';

Explanation:
Used escape character to search actual % symbol.

  1. Titles containing underscore (_)

SELECT *
FROM film
WHERE title LIKE '%_%' ESCAPE '\';

Explanation:
_ is special, so escaped it using .

  1. Titles start with A or B and end with s

SELECT *
FROM film
WHERE (title LIKE 'A%' OR title LIKE 'B%')
AND title LIKE '%s';

Explanation:
Combined start and end conditions.

  1. Titles with Man, Men, or Woman

SELECT *
FROM film
WHERE title LIKE '%Man%'
OR title LIKE '%Men%'
OR title LIKE '%Woman%';

Explanation:
Checked multiple words using OR.

  1. Titles containing digits

SELECT *
FROM film
WHERE title ~ '[0-9]';

Explanation:
Used regex to find numbers in title.

  1. Titles containing backslash ()

SELECT *
FROM film
WHERE title LIKE '%\%';

Explanation:
Used double backslash to match single backslash.

  1. Titles containing Love or Hate

SELECT *
FROM film
WHERE title LIKE '%Love%'
OR title LIKE '%Hate%';

Explanation:
Filtered titles containing specific words.

  1. First 5 movies ending with er, or, ar

SELECT *
FROM film
WHERE title LIKE '%er'
OR title LIKE '%or'
OR title LIKE '%ar'
LIMIT 5;

Explanation:
Checked ending patterns and limited to 5 rows.

Top comments (0)