Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Aggregate Sales With Time Zones
00:00
5 left

Aggregate Sales With Time Zones

MediumSQL · PostgreSQL

Problem

Write a query to aggregate sales data while handling time-zone complexities at Wayfair.

Use the provided sales and fulfillment-center data. Include completed sales with non-null amounts and convert each sale to the local calendar date of its fulfillment center.

Output

  1. One row per fulfillment center and local sale date.
  2. Columns: center_name, local_sale_date, order_count, and gross_sales.
  3. Exclude sales without a matching fulfillment center, a valid time zone, or a qualifying amount and status.
  4. Order by local_sale_date, then center_name.

Schema

sales_orders
ColumnTypeDescription
order_idPKINTUnique sales order identifier
center_idINTFulfillment center associated with the sale
occurred_atTIMESTAMPTZSale timestamp stored with its absolute time-zone offset
statusVARCHAR(20)Current order status
sale_amountNUMERIC(10,2)Gross amount for the sale
fulfillment_centers
ColumnTypeDescription
center_idPKINTUnique fulfillment center identifier
center_nameVARCHAR(100)Fulfillment center name
time_zoneVARCHAR(64)IANA time-zone name for the center
Tablessales_ordersfulfillment_centers
Interviewer

Your question is Aggregate Sales With Time Zones. 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.