-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path620_Not_Boring_Movies.sql
38 lines (29 loc) · 1.57 KB
/
620_Not_Boring_Movies.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Source: https://leetcode.com/problems/not-boring-movies/?envType=study-plan-v2&envId=top-sql-50
-- Table: Cinema
-- +----------------+----------+
-- | Column Name | Type |
-- +----------------+----------+
-- | id | int |
-- | movie | varchar |
-- | description | varchar |
-- | rating | float |
-- +----------------+----------+
-- 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.
-- rating is a 2 decimal places float in the range [0, 10]
-- 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.
------------------------------------------------------------------------------
-- SQL Schema
Create table If Not Exists cinema (id int, movie varchar(255), description varchar(255), rating float(2, 1))
Truncate table cinema
insert into cinema (id, movie, description, rating) values ('1', 'War', 'great 3D', '8.9')
insert into cinema (id, movie, description, rating) values ('2', 'Science', 'fiction', '8.5')
insert into cinema (id, movie, description, rating) values ('3', 'irish', 'boring', '6.2')
insert into cinema (id, movie, description, rating) values ('4', 'Ice song', 'Fantacy', '8.6')
insert into cinema (id, movie, description, rating) values ('5', 'House card', 'Interesting', '9.1')
-- MS SQL Server Code
SELECT id, movie, description, rating
FROM Cinema c
WHERE id % 2 <> 0 AND description <> 'boring'
ORDER BY rating DESC