返回介绍

solution / 1600-1699 / 1683.Invalid Tweets / README_EN

发布于 2024-06-17 01:03:15 字数 2531 浏览 0 评论 0 收藏 0

1683. Invalid Tweets

中文文档

Description

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.

 

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    | Vote for Biden           |
| 2    | Let us make America great again! |
+----------+----------------------------------+
Output: 
+----------+
| tweet_id |
+----------+
| 2    |
+----------+
Explanation: 
Tweet 1 has length = 14. It is a valid tweet.
Tweet 2 has length = 32. It is an invalid tweet.

Solutions

Solution 1: Using CHAR_LENGTH Function

The CHAR_LENGTH() function returns the length of a string, where Chinese characters, numbers, and letters are all counted as $1$ byte.

The LENGTH() function returns the length of a string, where under utf8 encoding, Chinese characters are counted as $3$ bytes, while numbers and letters are counted as $1$ byte; under gbk encoding, Chinese characters are counted as $2$ bytes, while numbers and letters are counted as $1$ byte.

For this problem, we can directly use the CHAR_LENGTH function to get the length of the string, and filter out the tweet IDs with a length greater than $15$.

# Write your MySQL query statement below
SELECT
  tweet_id
FROM Tweets
WHERE CHAR_LENGTH(content) > 15;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文