Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Revenue Per User SQL

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Average Revenue Per User SQL. Start with the requirements and the two tables on the right.

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.

Problem

Quantiphi's customer analytics reporting team needs the average revenue per registered user for the first two months of 2024. Revenue should include only completed payments made during the reporting period, while users with no qualifying revenue must remain in the denominator.

Write a PostgreSQL query to calculate ARPU, defined as total completed payment revenue divided by the total number of registered users.

Requirements

  1. Include every user in the denominator, including users with no matching payment.
  2. Include only payments with status = 'completed' from 2024-01-01 through 2024-02-29.
  3. Treat NULL payment amounts and users without qualifying payments as zero revenue, and return ARPU rounded to two decimal places.

Schema

users
ColumnTypeDescription
user_idPKINTUnique registered user identifier
user_nameVARCHAR(100)User display name
acquisition_channelVARCHAR(50)User registration channel
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
user_idINTUser associated with the payment
payment_dateDATEPayment recording date
amountDECIMAL(10,2)Payment amount
statusVARCHAR(20)Payment processing status
Tablesuserspayments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results