1683. Invalid Tweets
Problem Statement
Table: Tweets
Column Name | Type |
---|---|
tweet_id | int |
content | varchar |
tweet_id
is theprimary key
for this table. This table contains the all the tweets in a social media app.
Instructions
- 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
. - Return the result table in any order.
- The result format is in the following example.
Example
Input: Tweets
table
tweet_id | content |
---|---|
1 | "Sunny day" |
2 | "I love coding" |
Output:
tweet_id |
---|
2 |
Explanation:
The content of the tweet with
tweet_id
1 is "Sunny day" and the number of characters used iswhich is not strictly greater than . The content of the tweet with
tweet_id
2 is "I love coding" and the number of characters used iswhich is not strictly greater than .
Submissions
sql
SELECT tweet_id
FROM Tweets
WHERE CHAR_LENGTH(content) > 15;
python
import pandas as pd
def invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame:
return tweets[tweets['content'].str.len() > 15][['tweet_id']]
Explanations
PostgreSQL
Submitted by @noeyislearning
SELECT tweet_id
: This part of the statement specifies the column that you want to retrieve from the database. In this case, you're retrieving thetweet_id
column.FROM Tweets
: This part of the statement specifies the table from which you want to retrieve the data. Here,Tweets
is the table.WHERE CHAR_LENGTH(content) > 15
: This is a condition that filters the rows to include in the result set. It only includes rows where the character length of thecontent
column is greater than 15. TheCHAR_LENGTH
function returns the number of characters in a string.
Pandas
Submitted by @noeyislearning