Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Aggregate Metrics by Customer Segment

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

Your question is Aggregate Metrics by Customer 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

Huntington's Data Analytics team needs a segment-level view of customer activity for the first half of 2025. Write a PostgreSQL query that reports metrics for every Huntington customer segment, including segments with no assigned customers or no qualifying transactions.

Requirements

  1. Return the customer count, transaction count, deposit volume, loan payment volume, and average transaction amount for each segment.
  2. Include only transactions from January 1 through June 30, 2025, while preserving segments and customers without qualifying transactions.
  3. Use conditional aggregation for deposit and loan payment volumes, replace missing volume totals with zero, round average amounts to two decimals, and sort by segment name.

Schema

customer_segments
ColumnTypeDescription
segment_idPKINTUnique customer segment identifier
segment_nameVARCHAR(50)Huntington customer segment name
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
segment_idINTAssigned customer segment
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
customer_idINTCustomer associated with the transaction
transaction_typeVARCHAR(30)Transaction classification
amountDECIMAL(12,2)Transaction amount
transaction_dateDATEDate the transaction occurred
Tablescustomer_segmentscustomerstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results