https://leetcode.com/problems/not-boring-movies/description/
더보기
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.
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.
▶️ 내 코드(정답)
select *
from cinema
where id%2 = 1
and description not like '%boring%'
order by rating desc
👁️👁️ 참고할 코드 (MOD 활용)
SELECT * FROM Cinema
WHERE MOD(id, 2) <> 0 AND description <> 'boring'
ORDER BY rating DESC
MOD(나눌 값 혹은 컬럼 / 나눌 숫자) -> 나머지 출력
위 코드는 id 컬럼의 값들을 2로 나눴을 때, 0이 아닌 나머지,
즉 나머지가 1인 홀수 id들을 걸러주는 조건을 준 것이다.
++참고
FLOOR (나눠질 값 혹은 컬럼 / 나눌 숫자) -> 몫 출력
'SQL > 예제로 익히는 SQL 함수' 카테고리의 다른 글
[MySQL] DATEDIFF, TIMESTAMPDIFF, INTERVAL (0) | 2024.05.30 |
---|---|
[컬럼 만들기] 회원가입 각 단계 전환율 구하기 - SQL Challenge 세션 과제2 (0) | 2024.05.30 |
[SQL] 이동평균을 통해 매출 추이 살펴보기 (1) | 2024.05.23 |
총량 + 특정 조건 동시에 집계하기 (SUM(CASE WHEN ...)) (0) | 2024.05.14 |
JOIN | ON절과 WHERE절의 차이점 (0) | 2024.05.13 |