Consider the following tables
users tweets
--------------------------------- ---------------------------
user_id num_retweets sum_retweets tweet_id user_id retweeted
--------------------------------- ---------------------------
1 1 1 3
2 2 1 0
3 3 1 4
4 2 0
5 2 0
6 3 1
7 3 2
8 3 0
I want to count num_retweets: the number of times a users has written a retweet that has been retweeted and sum_retweets: the number of times all of a users tweets have been retweeted. The expected users table after the UPDATE query is:
users
---------------------------------
user_id num_retweets sum_retweets
---------------------------------
1 2 7 <-- 3 + 4
2 0 0
3 2 3 <-- 1 + 2
Any help on building these two queries would be greatly appreaciated 🙂 I keep having trouble performing UPDATEs across tables.
1 Answer