Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Monthly Revenue by Segment

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

Your question is Monthly Revenue by Segment. Start with the requirements and the three 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

Regions Financial wants a monthly view of revenue generated across its customer segments. Write a PostgreSQL query that summarizes posted transaction revenue for the first quarter of 2025.

Requirements

  1. Join customers to customer_segments and card_transactions using their related keys.
  2. Include only transactions with status = 'posted' from January through March 2025, using a half-open date range.
  3. Group revenue by calendar month and customer segment, and sort chronologically by month and alphabetically by segment.
  4. Ignore transactions that cannot be associated with a valid customer or segment.

Schema

customer_segments
ColumnTypeDescription
segment_idPKINTUnique customer segment identifier
segment_nameVARCHAR(50)Business name of the customer segment
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer's display name
segment_idINTReference to customer_segments
card_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
customer_idINTReference to customers
posted_atDATEDate the transaction was posted
revenue_amountDECIMAL(12,2)Revenue amount associated with the transaction
statusVARCHAR(20)Processing status of the transaction
Tablescustomer_segmentscustomerscard_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results