[SQL 문제 풀이] Not Boring Movies (지루하지 않은 영화)

Stupefyee's avatar
May 16, 2025
[SQL 문제 풀이] Not Boring Movies (지루하지 않은 영화)
Not Boring Movies - LeetCode
Can you solve this real interview question? Not Boring Movies - 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.
Not Boring Movies - LeetCode
notion image
홀수 번호 ID와 "지루하지 않은" 설명으로 영화를 보고할 수 있는 해결책을 작성하세요. 순위별로 정렬된 결과 테이블을 내림차순으로 반환합니다.
 

내가 작성한 쿼리

Oracle

SELECT * FROM Cinema WHERE description NOT LIKE 'boring' AND MOD(id, 2) = 1 ORDER BY rating DESC;

MySQL

SELECT * FROM Cinema WHERE description NOT LIKE 'boring' AND id % 2 = 1 ORDER BY rating DESC;

차이점

  • 홀수 구하는 방식의 차이
    • Oracle: MOD(인수1, 인수2)를 활용하여 나머지 계산
    • MySQL: %를 활용하여 나머지 계
Share article

stupefyee