Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Partitioning for Historical Data
00:00
5 left

Partitioning for Historical Data

MediumSQL · PostgreSQL

Problem

How would you use partitioning to improve query performance on large historical datasets in TaskRabbit’s warehouse?

Write a PostgreSQL query against the provided date-partitioned task_events table. Return monthly metrics for the first quarter of 2024, while preserving category-level month-over-month booking value comparisons. The date range must be bounded so historical partitions outside the requested period can be excluded.

Output

  1. One row per category and month with event data in Q1 2024
  2. Columns: category_name, month_start, completed_tasks, total_booking_value, prior_month_value, and value_change
  3. Include zero-value months that have events but no completed tasks
  4. Sort by category_name, then month_start

Schema

task_events
ColumnTypeDescription
event_idPKINTUnique task event identifier
task_idINTTask associated with the event
category_idINTTask category reference
event_dateDATEEvent date and partitioning column
statusVARCHAR(40)Task event status
booking_amountNUMERIC(12,2)Booking amount associated with the event
task_categories
ColumnTypeDescription
category_idPKINTUnique category identifier
category_nameVARCHAR(80)Task category name
Tablestask_eventstask_categories
Interviewer

Your question is Partitioning for Historical Data. Start with the requirements and the two 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.