Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Weekly Regional Performance

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

Your question is SQL for Weekly Regional Performance. 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

Amazon Kuiper Commercial Services needs a weekly operational view by reporting region. Write a PostgreSQL query for the weeks beginning January 6, January 13, and January 20, 2025.

Requirements

  1. Include every reporting region for every requested week, including weeks with no completed operations.
  2. Count total handled volume using volume_units from completed operations joined to an active service channel.
  3. Calculate average handling time in hours from opened_at to completed_at, rounded to two decimals.
  4. Use LAG to calculate week-over-week volume change as a percentage. Return NULL when the prior week has zero or no volume.
  5. Exclude non-reporting regions, incomplete operations, inactive channels, operations outside the three-week range, and operations with no matching region.
  6. Sort by region name and week start.

Schema

regions
ColumnTypeDescription
region_idPKINTEGERUnique operational region identifier
region_nameVARCHAR(80)Kuiper Commercial Services region name
is_reporting_regionBOOLEANWhether the region is included in reporting
service_channels
ColumnTypeDescription
channel_idPKINTEGERUnique service channel identifier
channel_nameVARCHAR(80)Operational intake channel name
is_activeBOOLEANWhether the channel is active
operational_cases
ColumnTypeDescription
operation_idPKBIGINTUnique operation identifier
region_idINTEGERRegion assigned to the operation
channel_idINTEGERService channel used by the operation
statusVARCHAR(20)Current operation status
volume_unitsINTEGERNumber of units handled
opened_atTIMESTAMPOperation start timestamp
completed_atTIMESTAMPOperation completion timestamp
Tablesregionsservice_channelsoperational_cases
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results