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
Monthly Revenue by Segment with Unclassified Customers
00:00
5 left

Monthly Revenue by Segment with Unclassified Customers

MediumSQL · PostgreSQL

Problem

Can you describe a scenario where you would choose a specific data modeling technique over another?

Using the supplied schema, write a query that produces an analytics-ready monthly revenue result. The query should include completed orders only and handle customers without a populated segment.

Output

  1. One row per customer segment and calendar month
  2. Columns: segment, revenue_month, completed_orders, revenue
  3. Include only segments with completed revenue, order by segment ascending and revenue_month ascending

Output details

  • Represent missing segments as Unclassified.
  • Represent revenue_month as the first day of each calendar month.
  • Calculate completed_orders as distinct order counts.
  • Calculate revenue as the sum of quantity * unit_price.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
segmentVARCHAR(30)Customer reporting segment
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer associated with the order
order_dateDATEDate the order was placed
statusVARCHAR(20)Current order status
order_items
ColumnTypeDescription
order_item_idPKINTUnique order item identifier
order_idINTOrder containing the item
product_nameVARCHAR(80)Name of the purchased product
quantityINTUnits purchased
unit_priceNUMERIC(10,2)Price per unit
Tablescustomersordersorder_items
Interviewer

Your question is Monthly Revenue by Segment with Unclassified Customers. 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.