Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compare Current vs Historical Customer Behavior

Hard
SQL & Data ManipulationWindow FunctionsLag/LeadDate FunctionsAsked 4 times

Problem

Write a PostgreSQL query that compares each customer's latest active month on ACME House with their own prior 3-month baseline. Use only completed orders, aggregate behavior by calendar month, and return customers only when a full 3-month history exists.

Schema

ColumnTypeDescription
order_idINT
customer_idINT
order_dateDATE
order_statusVARCHAR(20)
order_amountNUMERIC(10,2)
channelVARCHAR(20)

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
SELECT ...
FROM ...
JOIN ... ON ...
GROUP BY ...
HAVING ...
ORDER BY ... DESC;
Sign up to unlock solutions
Applied Systems Data Scientist Interview QuestionsBASF Data Scientist Interview QuestionsQuantium Data Scientist Interview QuestionsBASF Interview QuestionsApplied Systems Interview Questions
Next questions
QantasTrack Monthly Customer Activity ChangesHardMonthly Customer Spend and RankMediumAmerican ExpressCompare Spend Across Card SegmentsMedium
PostgreSQL