0

this query gives top 5 number of tweets, username and number of tweets thay have

 SELECT users.username, COUNT(tweet.content) as tweet _count
                       FROM tweets
                       INNER JOIN users 
                       ON tweets.userid=users.id
                       GROUP BY userid ORDER BY tweet_count DESC
                       LIMIT 5

to explain further here are the tables involved

retweets table is composed of

id, tweet_id, userid, date_created

tweets table is composed of

id, userid, content, date_created

users table is composed of

id and username

as you can see retweets use the content of the tweets table through tweet_id and user_id.

now the problem is i want a query that gives top 5 number of retweets, username and number of retweets thay have..

im kinda confused with joining several tables and i keep getting errors when i try. THANKS FOR YOUR HELP!

4

1 回答 1

0
SELECT users.username,count(retweet.id) as retweets 
                       FROM retweets
                       LEFT JOIN tweets
                       ON retweets.tweet_id=tweets.id
                       INNER JOIN Users 
                       ON retweets.userid=users.id
                       GROUP BY userid
                       LIMIT 5
于 2013-03-29T08:26:28.950 回答