LeetCode SQL 1683. Invalid Tweets【SELECT】简单
发布日期:2021-07-01 02:58:23 浏览次数:2 分类:技术文章

本文共 1292 字,大约阅读时间需要 4 分钟。

Table: Tweets

+----------------+---------+| Column Name    | Type    |+----------------+---------+| tweet_id       | int     || content        | varchar |+----------------+---------+tweet_id is the primary key for this table.This table contains all the tweets in a social media app.

Write an SQL query 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 query result format is in the following example:

Tweets table:+----------+----------------------------------+| tweet_id | content                          |+----------+----------------------------------+| 1        | Vote for Biden                   || 2        | Let us make America great again! |+----------+----------------------------------+Result table:+----------+| tweet_id |+----------+| 2        |+----------+Tweet 1 has length = 14. It is a valid tweet.Tweet 2 has length = 32. It is an invalid tweet.

题意:写一个 SQL 查询,找出无效的推特。


解法 SELECTLENGTH

MySQL中计算字段的长度,有两个函数:

  • LENGTH:一个用来获取字符串长度的内置函数,其中一个汉字算作三个字符,一个数字或字母算作一个字符
  • CHAR_LENGTH:不管汉字还是数字或者是字母,都算是一个字符
SELECT tweet_idFROM TweetsWHERE LENGTH(content) > 15;

运行结果如下:

执行用时:435 ms, 在所有 MySQL 提交中击败了100.00% 的用户内存消耗:0 B, 在所有 MySQL 提交中击败了100.00% 的用户

转载地址:https://memcpy0.blog.csdn.net/article/details/111406220 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode SQL 1693. Daily Leads and Partners【SELECT】简单
下一篇:LeetCode C++ 1688. Count of Matches in Tournament【Math】简单

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月21日 19时13分23秒