Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top 10% Pinners by Promoted Engagement
00:00
5 left

Top 10% Pinners by Promoted Engagement

MediumSQL · PostgreSQL

Problem

How would you write a SQL query to identify the top 10% of Pinners based on their engagement with promoted pins on Pinterest?

Use all Pinners, including those with no qualifying engagement. Rank by total engagement descending, break ties by pinner_id ascending, and use the ceiling of 10% when the population size does not divide evenly.

Output

  1. One row per selected Pinner with pinner_id, username, total_engagements, and engagement_rank
  2. Include only the top 10%, ordered by engagement_rank ascending, then pinner_id ascending

Schema

pinners
ColumnTypeDescription
pinner_idPKINTUnique identifier for a Pinner
usernameVARCHAR(100)Pinterest username
promoted_pins
ColumnTypeDescription
promoted_pin_idPKINTUnique identifier for a promoted Pin
pinner_idINTPinner who owns or published the promoted Pin
pin_titleVARCHAR(150)Short title of the promoted Pin
statusVARCHAR(20)Promotion status
promoted_pin_engagements
ColumnTypeDescription
engagement_idPKINTUnique identifier for an engagement event
promoted_pin_idINTPromoted Pin associated with the engagement
pinner_idINTPinner who generated the engagement
engagement_typeVARCHAR(30)Type of engagement event
Tablespinnerspromoted_pinspromoted_pin_engagements
Interviewer

Your question is Top 10% Pinners by Promoted Engagement. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.