Skip to main content
All Questions

Post Success By Age Group.

Medium
Unlock detailed company stats for this questionUpgrade

You are given the following tables:

Sample Data

post table:

post_idpost_dateuser_idinterfaceis_successful_post
12024-01-051mobiletrue
22024-01-122webfalse
32024-01-203mobiletrue
42024-02-034webtrue
52024-02-141mobilefalse
62024-02-225webtrue

post_user table:

user_iduser_typeage
1standard16
2standard34
3premium12
4standard45
5premium28

Examples

Output: post_month | ya_sc_rate | non_ya_sc_rate | diff -----------|------------|----------------|------ 1 | 1.00 | 0.00 | 1.00 2 | 0.00 | 1.00 | -1.00

Explanation:

  • Month 1: Young adults (users 1, 3 — ages 16 and 12) had 2 posts, both successful → ya_sc_rate = 1.00. Non-young adult (user 2, age 34) had 1 post, unsuccessful → non_ya_sc_rate = 0.00. diff = 1.00 - 0.00 = 1.00
  • Month 2: Young adult (user 1, age 16) had 1 post, unsuccessful → ya_sc_rate = 0.00. Non-young adults (users 4, 5) had 2 posts, both successful → non_ya_sc_rate = 1.00. diff = 0.00 - 1.00 = -1.00

Results are ordered by ascending month.

Write a SQL that shows the difference in success rate of posting dropoff between young adults (age 0-18) and non young adults by each week.

The output should look like per month, the young adult success rate for posting, non-young adult success rate for posting and dropoff between the two.

Your output should contain the following columns: post_month, ya_sc_rate (young adults success rate), non_ya_sc_rate (non young adults success rates), diff (difference between the ya_sc_rate and non_ya_sc_rate rounded to 2 decimal place). Order by ascending month.

Related courses

Course

Data Analyst Interview Prep

Ace your data analyst interviews—whether you're targeting product, marketing, or business analyst roles. Tackle real take-home case studies, sharpen your technical and dashboarding skills, and get strategies from interviewers at top tech companies and startups.

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.