Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Aggregate by Category and Date

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

Your question is Aggregate by Category and Date. Start with the requirements and the one table 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

Synechron's Analytics Platform team tracks daily revenue across service categories. Write a PostgreSQL query that summarizes this activity by category and transaction date.

Requirements

  1. Return one row for each category and transaction date combination.
  2. Calculate the number of transactions and total revenue for each group, including groups where an individual revenue value is NULL.
  3. Sort the output by category alphabetically and transaction date chronologically.

Schema

service_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
categoryVARCHAR(50)Synechron service category
transaction_dateDATEDate of the transaction
revenueDECIMAL(12,2)Transaction revenue, which may be NULL
Tablesservice_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results