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
Writing Complex Queries
00:00
5 left

Writing Complex Queries

HardSQL · PostgreSQL

Problem

How would you write complex queries to answer a business question?

Using the supplied customer, order, order item, and support ticket data, produce a monthly performance view for active customers from January through March 2025. Include completed-order revenue, month-over-month revenue change, regional revenue rank, a three-month rolling revenue total, and support ticket volume.

Output

  1. One row per active customer and calendar month.
  2. Columns: customer_id, customer_name, region, month, monthly_revenue, prior_month_revenue, revenue_growth_pct, regional_monthly_rank, rolling_3_month_revenue, and support_ticket_count.
  3. Include months with no revenue as zero, order by month, region, regional_monthly_rank, and customer_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTCustomer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(30)Customer sales region
is_activeBOOLEANWhether the customer is active
orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTOrdering customer
order_dateDATEDate the order was placed
order_statusVARCHAR(20)Order lifecycle status
order_items
ColumnTypeDescription
order_item_idPKINTOrder item identifier
order_idINTParent order
quantityINTQuantity purchased
unit_priceNUMERIC(10,2)Price per unit
discountNUMERIC(10,2)Order-line discount
support_tickets
ColumnTypeDescription
ticket_idPKINTSupport ticket identifier
customer_idINTCustomer who opened the ticket
opened_atDATETicket opening date
ticket_statusVARCHAR(20)Ticket status
Tablescustomersordersorder_itemssupport_tickets
Interviewer

Your question is Writing Complex Queries. Start with the requirements and the four 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.