알고리즘

[SQL] 1683. Invalid Tweets (Easy)

파뱁 2024. 12. 26. 15:45
728x90

LENGTH() 함수를 써보는 문제

https://leetcode.com/problems/invalid-tweets/description/?envType=study-plan-v2&envId=top-sql-50

⬆️ 문제 전문 링크

 

Table: Tweets

+----------------+---------+
| Column Name    | Type    |
+----------------+---------+
| tweet_id       | int     |
| content        | varchar |
+----------------+---------+
tweet_id is the primary key (column with unique values) for this table.
content consists of characters on an American Keyboard, and no other special characters.
This table contains all the tweets in a social media app.
 

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.

The result format is in the following example.

 

Example 1:

Input: 
Tweets table:
+----------+-----------------------------------+
| tweet_id | content                           |
+----------+-----------------------------------+
| 1        | Let us Code                       |
| 2        | More than fifteen chars are here! |
+----------+-----------------------------------+
Output: 
+----------+
| tweet_id |
+----------+
| 2        |
+----------+
Explanation: 
Tweet 1 has length = 11. It is a valid tweet.
Tweet 2 has length = 33. It is an invalid tweet.

 

Tweets  테이블에서 content의 글자수가 15를 넘어가면 잘못된 형식의 트윗이라 판단하고 이를 추출하는 문제로

LENGTH([컬럼명]) 함수를 사용하면 된다.

 

풀이는 다음과 같다.

 

select tweet_id 
from Tweets
where LENGTH(content) > 15;
728x90
반응형