Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.