Given a Tweets table containing user tweets from February 2024, find the top 3 trending hashtags.
Each tweet may contain multiple hashtags (words starting with #). You need to:
- Extract all hashtags from tweet text
- Count frequency of each hashtag
- Return top 3 hashtags ordered by count (descending), then by hashtag name (descending)
Table: Tweets
| Column Name | Type |
|---|---|
| user_id | int |
| tweet_id | int |
| tweet_date | date |
| tweet | varchar |
tweet_id is the primary key. All tweet_date values are valid dates in February 2024.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
|
int | User identifier |
tweet_id
PK
|
int | Unique tweet identifier (primary key) |
tweet_date
|
date | Date when tweet was posted (February 2024) |
tweet
PK
|
varchar | Tweet content text that may contain hashtags |
Input & Output
| user_id | tweet_id | tweet_date | tweet |
|---|---|---|---|
| 1 | 1 | 2024-02-01 | Loving the new #AI features! #tech #innovation |
| 2 | 2 | 2024-02-02 | Just tried #AI for coding. Mind blown! #tech |
| 3 | 3 | 2024-02-03 | The future is here with #AI technology #future |
| 4 | 4 | 2024-02-04 | Working on #innovation projects today |
| hashtag | hashtag_count |
|---|---|
| #AI | 3 |
| #tech | 2 |
| #innovation | 2 |
#AI appears 3 times (tweets 1,2,3), #tech appears 2 times (tweets 1,2), and #innovation appears 2 times (tweets 1,4). Since #tech and #innovation both have count 2, they're ordered by hashtag name descending, so #tech comes before #innovation.
| user_id | tweet_id | tweet_date | tweet |
|---|---|---|---|
| 1 | 1 | 2024-02-01 | Love #python programming #coding |
| 2 | 2 | 2024-02-02 | Working with #java today #coding |
| 3 | 3 | 2024-02-03 | Learning #javascript fundamentals |
| hashtag | hashtag_count |
|---|---|
| #coding | 2 |
| #python | 1 |
| #javascript | 1 |
#coding appears 2 times. The other hashtags appear once each. Among equal counts, we order by hashtag name descending: #python > #javascript > #java alphabetically reversed.
Constraints
-
1 ≤ user_id ≤ 1000 -
1 ≤ tweet_id ≤ 10000 -
tweet_dateis a valid date in February 2024 -
1 ≤ tweet.length ≤ 280 -
Hashtags start with
#and contain alphanumeric characters