How to Find Invalid Tweets with SQL Query | MySQL CHAR_LENGTH Tutorial

2023-12-26 08:49:20

Title description

The question will give us aTweetsInformation sheet. There are fields such as tweet_id and content respectively.The tweet_id of this data table isprimary keyPrimary key。

The question asks us to list all illegal tweets. The output order is arbitrary.

The definition of illegal tweets is that the length of the tweet content exceeds 15 characters.

Table: Tweets

+—————-+———+
| Column Name | Type |
+—————-+———+
| tweet_id | int |
| content | varchar |
+—————-+———+
tweet_id is the primary key (column with unique values) for this table.
This table contains all the tweets in a social media app.

Detailed questions can be found here

Restrictions

List all illegal tweets longer than 15 characters.

Answers are output in any order.

algorithm

SELECT …field

FROM …data table

WHERE …filter criteria

Just bring it in according to the meaning of the question. The main focus of this question is the string function CHAR_LENGTH().

Counts and returns the total number of characters in a given string.

CHAR_LENGTH Tutorial Teaching

Program code

SELECT tweet_id
FROM Tweets
WHERE CHAR_LENGTH(content) > 15;

Key knowledge points

Think of the standard template for SQL queries and just bring it in according to the meaning of the question.

​SELECT …field

FROM …data table

WHERE …filter criteria

The main focus of this question lies in the string function CHAR_LENGTH().

Counts and returns the total number of characters in a given string.

Reference:

[1] MySQL by CHAR_LENGTH(…) > 15 – Invalid Tweets – LeetCode

1703581969
#SQL #function #CHAR_LENGTH #illegal #tweet #Leetcode

Leave a Replay