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
Start free
Design a Customer Schema
00:00
5 left

Design a Customer Schema

MediumSQL · PostgreSQL

Problem

How would you design a customer schema table and answer the follow-up SQL questions?

Use the supplied customer, order, and order-item tables. Return a customer-level summary based only on completed orders, while retaining customers who have no completed orders.

Output

  1. One row per customer with customer_id, full_name, completed_order_count, completed_spend, latest_completed_order_date, and customer_segment.
  2. Include all customers, using zero spend and a NULL latest date when applicable.
  3. Sort by completed_spend descending, then customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
full_nameVARCHAR(120)Customer's full name
emailVARCHAR(255)Customer email address
country_codeVARCHAR(2)Two-letter customer country code
customer_statusVARCHAR(20)Current customer status
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_statusVARCHAR(20)Order lifecycle status
order_dateDATEDate the order was placed
order_items
ColumnTypeDescription
order_item_idPKINTUnique order-line identifier
order_idINTOrder containing the item
product_nameVARCHAR(120)Name of the ordered item
quantityINTNumber of units ordered
unit_priceNUMERIC(10,2)Price per unit
Tablescustomersordersorder_items
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.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.