반응형
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 alphanumeric characters, '!', or ' ' 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.
트윗의 글자 수가 15자를 초과하면 invalid로 간주하는 간단한 문자열 길이 필터링 문제입니다.
SELECT tweet_id
FROM Tweets
WHERE CHAR_LENGTH(content) > 15;
MySQL에서는 문자열의 길이를 구할 때 CHAR_LENGTH() 함수를 사용할 수 있습니다. 위 쿼리를 실행하면 다음과 같이 트윗의 글자 수가 15자를 초과한 경우의 ID만 출력됩니다.
반응형
'Computer Science > SQL' 카테고리의 다른 글
SQL | LeetCode 197. 셀프 조인(Self Join)과 DATE_ADD를 활용한 날짜 비교 문제 (0) | 2025.05.02 |
---|---|
SQL | LeetCode 1581. 방문은 했지만 거래는 없던 고객 찾기 (RIGHT JOIN & GROUP BY 예제) (2) | 2025.05.01 |
SQL | LeetCode 584. 조건문으로 필터링하기 (0) | 2025.04.29 |
SQL | 실습으로 배우는 SQL 문법 - 2 (0) | 2025.04.28 |
SQL | 실습으로 배우는 SQL 문법 - 1 (0) | 2025.04.27 |