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

[LeetCode][SQL50] #5. Invalid Tweets

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

๐Ÿ’ป ๋ฌธ์ œ ์ฃผ์†Œ : Invalid Tweets - LeetCode

 

Invalid Tweets - LeetCode

Can you solve this real interview question? Invalid Tweets - Table: Tweets +----------------+---------+ | Column Name | Type | +----------------+---------+ | tweet_id | int | | content | varchar | +----------------+---------+ tweet_id is the primary key (c

leetcode.com

 

๐Ÿ’ป ๋ฌธ์ œ

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15. Return the result table in any order.

- ์œ ํšจํ•˜์ง€ ์•Š์€ ํŠธ์œ— ID๋ฅผ ์ฐพ์œผ์‹œ์˜ค. 15๊ธ€์ž ์ด์ƒ์ผ ๊ฒฝ์šฐ ์œ ํšจํ•˜์ง€ ์•Š์œผ๋ฉฐ, ์ถœ๋ ฅ ์ˆœ์„œ๋Š” ์ƒ๊ด€ ์—†์Šต๋‹ˆ๋‹ค.

Input๊ณผ Output ์˜ˆ์‹œ

 

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

select tweet_id
from Tweets
where length(content) > 15

 

 

 ์œ„ ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ ํ•ต์‹ฌ์€ ๋ฐ”๋กœ ์•„๋ž˜ 1๏ธโƒฃ์ด๋‹ค.

1๏ธโƒฃ 15๊ธ€์ž ์ด์ƒ์ผ ๊ฒฝ์šฐ ์œ ํšจํ•˜์ง€ ์•Š์Œ

 

1๏ธโƒฃ 15๊ธ€์ž ์ด์ƒ์ผ ๊ฒฝ์šฐ ์œ ํšจํ•˜์ง€ ์•Š์Œ

MySQL์—์„œ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•  ๋• Length() ํ•จ์ˆ˜๋ฅผ ์“ด๋‹ค. 

select length('abc') -- 3

 

length() ํ•จ์ˆ˜๋Š” ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”๋ฐ, ์ด๋•Œ ๊ฐ€์ ธ์˜ค๋Š” ๋‹จ์œ„๊ฐ€ byte์ด๊ธฐ ๋•Œ๋ฌธ์— ์˜๋ฌธ์ด๋‚˜ ์ˆซ์ž์™€ ๊ฐ™์ด 1 byte๊ฐ€ ์•„๋‹Œ, 2 byte๋กœ ์ด๋ฃจ์–ด์ง„ ํ•œ๊ธ€์˜ ๊ฒฝ์šฐ ์˜๋„ํ•˜์ง€ ์•Š์€ ๊ฐ’์„ ๋ฆฌํ„ดํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ํ•œ๊ธ€์„ ์˜๋ฌธ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ธ€์ž ๋‹จ์œ„๋กœ ์„ธ๊ณ  ์‹ถ๋‹ค๋ฉด 'char_length()'๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋œ๋‹ค.

select length('๊ฐ€๋‚˜๋‹ค') -- 6 (2+2+2)
select char_length('๊ฐ€๋‚˜๋‹ค') -- 3

 

 

728x90
๋ฐ˜์‘ํ˜•

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

[LeetCode][SQL50] #7. Product Sales Analysis I  (0) 2023.11.07
[LeetCode][SQL50] #6. Replace Employee ID With The Unique Identifier  (0) 2023.11.07
[LeetCode][SQL50] #4. Article Views I  (0) 2023.11.06
[LeetCode][SQL50] #3. Big Countries  (0) 2023.11.06
[LeetCode][SQL50] #2. Find Customer Referee  (0) 2023.11.03