Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Fact and Dimension Tables
00:00
5 left

Fact and Dimension Tables

MediumSQL · PostgreSQL

Problem

What is Fact and Dimensions tables?

Asked in the technical screen stage. Data warehousing concept. Write a SQL query using the provided fact and dimension tables to summarize completed order facts.

Output

  1. One row per calendar month and product category.
  2. Columns: order_month, product_category, completed_orders, and total_revenue.
  3. Include completed facts even when a dimension lookup is missing, labeling missing dimension values as Unknown.
  4. Sort by order_month, then product_category.

Schema

fact_orders
ColumnTypeDescription
order_fact_idPKINTUnique order fact identifier
order_date_idINTReference to the calendar date dimension
product_idINTReference to the product dimension
quantityINTNumber of units in the order fact
unit_priceNUMERIC(10,2)Price per unit
order_statusVARCHAR(20)Order lifecycle status
dim_date
ColumnTypeDescription
date_idPKINTSurrogate key for the date dimension
calendar_dateDATECalendar date
month_nameVARCHAR(20)Calendar month name
dim_product
ColumnTypeDescription
product_idPKINTSurrogate key for the product dimension
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
Tablesfact_ordersdim_datedim_product
Interviewer

Your question is Fact and Dimension Tables. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.