Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Active Subscription Revenue by Customer

HardSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Active Subscription Revenue by Customer. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

PetBox wants a report of currently active subscriptions and the revenue tied to each subscribed product. Write a SQL query to return one row per active subscription.

Requirements

  1. Return the customer name, product name, next shipment date, and product price as revenue
  2. Include only subscriptions where status = 'active'
  3. Join subscriptions to customers and products using their keys
  4. Order the final result by customer name, then product name

Sample Output

customer_nameproduct_namenext_shipment_daterevenue
AliceDog Food2024-01-1529.99
BobCat Litter2024-01-2019.99
DianaCat Treats2024-01-309.99

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique identifier for each customer
nameVARCHAR(255)Customer's full name
emailVARCHAR(255)Customer email address
created_atTIMESTAMPTimestamp when the customer account was created
products
ColumnTypeDescription
product_idPKINTUnique identifier for each product
nameVARCHAR(255)Product name
categoryVARCHAR(255)Product category
priceDECIMAL(10,2)Product price
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique identifier for each subscription
customer_idINTReference to the customer
product_idINTReference to the product
start_dateDATEDate the subscription started
next_shipment_dateDATEDate of the next scheduled shipment
statusVARCHAR(255)Current subscription status
Tablescustomersproductssubscriptions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results