๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SQL/LeetCode

[LeetCode][SQL50] #15. Not Boring Movies

by ์ด๋ฎด 2023. 11. 13.
728x90

๐Ÿ’ป ๋ฌธ์ œ ์ฃผ์†Œ : Not Boring Movies - LeetCode

 

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 | +----------------

leetcode.com

 

๐Ÿ’ป ๋ฌธ์ œ

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 desceding order.

- ํ™€์ˆ˜ ID๊ฐ€ ๋ณธ ์˜ํ™” ๋ฐ ์„ค๋ช… ๋“ฑ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค. ์„ค๋ช…์€ 'boring'์ด ์•„๋‹ˆ์–ด์•ผ ํ•˜๋ฉฐ, ๊ฒฐ๊ณผ ํ…Œ์ด๋ธ”์€ rating์„ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’ป ์ฝ”๋“œ ๋ฐ ํ’€์ด 

select id, movie, description, rating
from Cinema
where mod(id, 2) = 1 and description != 'boring'
order by rating desc
 

โ˜ Mod(N, M)

Mod ํ•จ์ˆ˜๋Š” ์–ด๋– ํ•œ ์ˆ˜ N์„ M์œผ๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๋กœ, ํ™€์ง์„ ๊ตฌ๋ถ„ํ•  ๋•Œ ๋งŽ์ด ์“ด๋‹ค. Mod ํ•จ์ˆ˜๋Š” Mod(N, M) ํ˜•์‹ ์™ธ์—๋„ ๊ธฐ์กด C ์–ธ์–ด ๋“ฑ์—์„œ ์‚ฌ์šฉํ•˜๋Š” 'N % M' ํ˜•์‹์œผ๋กœ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

'SQL > LeetCode' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[LeetCode][SQL50] #17. Project Employees I  (0) 2023.11.15
[LeetCode][SQL50] #16. Average Selling Price  (0) 2023.11.14
[LeetCode][SQL50] #14. Confirmation Rate  (0) 2023.11.13
[LeetCode][SQL50] #13. Managers with at Least 5 Direct Reports  (0) 2023.11.09
[LeetCode][SQL50] #12. Students and Examinations  (0) 2023.11.09