Follow the money to developers

HardAppleunion allrefundscommissionrank per groupsubscription cohorts· 160 XP (40 per step)

Mock interview. You're interviewing for a senior analyst job on an app store's developer relations team. The interviewer says: "Developers make money three ways: paid downloads, in-app purchases and subscriptions. We want one clean view of the money, then a few cuts of it."

The rules for this interview:

  • A paid download is a first-time download (is_redownload false) of an app with price > 0, worth the app's price.
  • Every row in purchases is a sale worth price_usd. If refunded_on has a date, the money went back to the customer.
  • The store keeps a commission: 15% for developers in the small business program (small_business true), 30% for everyone else. The rest is the developer's proceeds.

Step 1: One view of every sale

"Put paid downloads and purchases into one list of sales, then show for each sale type: number of sales, gross amount, refunds and net (gross minus refunds)."

Expected output

  • sale_type is paid download for downloads and the purchase's product_type otherwise; refunds is 0 when there are none; sorted by net, highest first

Example of the shape (made-up values):

sale_type sales gross refunds net
paid download 2000 8000.00 0 8000.00

Hints, the later steps and the answer come with Pro.

Step 1 of 4

Write your query here. Ctrl + Enter submits.