728x90
문제는 여기서 확인할 수 있습니다.
Table: Cinema
+----------------+----------+
| Column Name | Type |
+----------------+----------+
| id | int |
| movie | varchar |
| description | varchar |
| rating | float |
+----------------+----------+
id is the primary key 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 an SQL query 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 query result format is in the following example.
Example 1:
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 |
+----+------------+-------------+--------+
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.
Code:
select *
from Cinema
where id % 2 = 1 and description <> "boring"
order by rating desc;
description != "boring" 이라고 해도 정답 처리가 된다.
where절에 and로 두 조건을 매우 직관적으로 써주어서 큰 어려움은 없는 문제이다.
728x90
'SQL' 카테고리의 다른 글
[프로그래머스/SQL] 없어진 기록 찾기 (0) | 2022.08.25 |
---|---|
[Leetcode/SQL] 626. Exchange Seats (0) | 2022.08.23 |
[Leetcode/SQL] 601. Human Traffic of Stadium (0) | 2022.08.21 |
[Leetcode/SQL] 185. Department Top Three Salaries (0) | 2022.08.21 |
[Leetcode/SQL] 596. Classes More Than 5 Students (0) | 2022.08.20 |