난이도: EASY
문제 링크: https://leetcode.com/problems/not-boring-movies/description/?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.
The 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.
체크할 개념
특정 컬럼이 홀수인지 짝수인지 아는 방법 : MOD(컬럼명, 2) 가 0이면 짝수, 1이면 홀수
SELECT id,
CASE
WHEN MOD(id, 2) = 0 THEN '짝수'
ELSE '홀수'
END AS 홀짝
FROM tempTbl;
나의 최종 제출 답안:
SELECT *
FROM Cinema
WHERE description <> 'boring'
AND MOD(id, 2) = 1
ORDER BY rating DESC
description이 boring이 아니면서 / id가 홀수인 컬럼을 / rating기준으로 내림차순으로 정렬하여 / 모든 정보 보여주기
WHERE description <> 'boring' / AND MOD(id, 2) = 1 / ORDER BY rating DESC / SELECT *
'Coding Challenges > LeetCode' 카테고리의 다른 글
[SQL50] 1251. Average Selling Price (0) | 2025.03.06 |
---|---|
[SQL50] 1729. Find Followers Count (0) | 2025.03.05 |
[SQL50] 596. Classes More Than 5 Students (0) | 2025.03.05 |
[SQL50] 1141. User Activity for the Past 30 Days I (1) | 2025.03.04 |
[SQL50] 2356. Number of Unique Subjects Taught by Each Teacher (0) | 2025.03.04 |