Description

Table: Cinema

Column NameType
idint
movievarchar
descriptionvarchar
ratingfloat
  • id is the primary key (column with unique values) for this table.
  • Each row contains information about the name of a movie, its genre, and its rating.
  • The rating is a 2 decimal places float in the range [0, 10]

Problem Statement

Write a solution to report the movies with an odd-numbered ID and a description that is not "boring".

Return the result table ordered by rating in descending order.

The result format is in the following example.

Example 1:

Input:

  • Cinema table:
idmoviedescriptionrating
1Wargreat 3D8.9
2Sciencefiction8.5
3irishboring6.2
4Ice songFantacy8.6
5House cardInteresting9.1

Output:

idmoviedescriptionrating
5House cardInteresting9.1
1Wargreat 3D8.9

Explanation:

  • We have three movies with odd-numbered IDs: 1, 3, and 5. The movie with ID = 3 is boring so we do not include it in the answer.

Solution

This is simple filter query where you need to filter by two conditions:

  1. id is odd. This is done using id % 2 = 1.
  2. description is not boring. This is done using description != 'boring'.

Finally, you need to order the result by rating in descending order.

1SELECT *
2    FROM Cinema
3    WHERE id % 2 = 1 AND description != 'boring'
4    ORDER BY rating DESC;