Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Revenue by Subscription Tier
00:00
5 left

SQL Revenue by Subscription Tier

MediumSQL · PostgreSQL

Problem

Given a schema with users, subscriptions, and payments, write a SQL query using joins and group by to find the total revenue generated per subscription tier last month.

Use calendar-month boundaries and include payment amounts recorded during the previous calendar month.

Output

  1. Return one row per subscription tier with columns subscription_tier and total_revenue.
  2. Include only tiers with matching users, subscriptions, and payments from last month.
  3. Order results alphabetically by subscription_tier.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
emailVARCHAR(255)User email address
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
user_idINTUser who owns the subscription
tierVARCHAR(50)Subscription tier
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
subscription_idINTSubscription associated with the payment
amountNUMERIC(10,2)Payment amount
paid_atDATEDate the payment was recorded
Tablesuserssubscriptionspayments
Interviewer

Your question is SQL Revenue by Subscription Tier. 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.