Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Star Schema and Facts

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

Your question is Star Schema and Facts. 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

Explain how you would model sales transactions using a star schema with a fact table and dimension tables.

Use the provided sales fact, product dimension, and date dimension structures. Write a PostgreSQL query that demonstrates the model by summarizing completed sales from the first quarter of 2025.

Output

  1. One row per calendar month and product category.
  2. Return month_start, category, transaction_count, total_quantity, and total_sales.
  3. Include unmatched products as Unknown, exclude canceled sales and dates outside the quarter, and sort by month_start then category.

Schema

fact_sales
ColumnTypeDescription
sale_idPKINTUnique sales transaction identifier
date_keyINTReference to the date dimension
product_keyINTReference to the product dimension
quantityINTNumber of units sold
unit_priceDECIMAL(10,2)Price per unit at the time of sale
sales_statusVARCHAR(20)Transaction status
dim_product
ColumnTypeDescription
product_keyPKINTSurrogate product dimension key
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
dim_date
ColumnTypeDescription
date_keyPKINTSurrogate date dimension key
calendar_dateDATECalendar date
Tablesfact_salesdim_productdim_date
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results