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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
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.

Output details

  • Filter facts where order_status equals Completed.
  • Format known order months as YYYY-MM, and label missing calendar dates as Unknown.
  • Compute completed_orders by counting every qualifying fact row without deduplication.
  • Compute total_revenue as the sum of quantity * unit_price, treating a NULL sum as 0.
  • Sort order_month and then product_category in ascending order.

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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

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.