← Interview questions
Meta logo

Average Shares Per Post

Meta·easy·SQL

You are given a table of posts and a table of post shares. Find the average number of shares per post for each user. Include users who have posts but received no shares, showing 0 for them. Return user_id and avg_shares_per_post rounded to 2 decimal places, ordered by user_id.

Schema

user_posts
post_idINTEGER
user_idINTEGER
contentVARCHAR
post_dateDATE
post_shares
share_idINTEGER
post_idINTEGER
shared_by_user_idINTEGER
shared_atTIMESTAMP

Target output

Target output
user_idavg_shares_per_post
1011.50
1020.00
1030.00
1042.00
1050.00
Queryuser_posts, post_shares
Cmd+Enterto runLoading...
Output

Loading sample data...