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
Star Schema and Facts
00:00
5 left

Star Schema and Facts

MediumSQL · PostgreSQL

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
Interviewer

Your question is Star Schema and Facts. Start with the requirements and the three 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.