Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Diagnose Inconsistent Customer Report

MediumSQL · PostgreSQL00:00
I
Practice interviewer
In session
5 left
00:00

Your question is Diagnose Inconsistent Customer Report. Start with the requirements and the three tables on the right.

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.

Problem

A customer report in AbbVie Customer 360 suddenly looks inconsistent from one week to the next. You are asked to write a SQL query that surfaces the first places you would investigate: customers whose latest weekly snapshot has a different segment, a different active flag, or a different total interaction count than the prior snapshot. Return one row per customer for the most recent snapshot date, along with the prior snapshot date, the current and previous values, and a change_type label showing whether the inconsistency is driven by a segment change, status change, interaction count change, or no prior snapshot.

Use the latest two snapshots available for each customer. Include only customers whose latest snapshot exists in the data, and count interactions that occurred on or before each snapshot date.

Schema

customer_profiles
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
regionVARCHAR(50)Commercial region
customer_weekly_snapshot
ColumnTypeDescription
snapshot_idPKINTSnapshot row identifier
customer_idINTReferences customer_profiles.customer_id
snapshot_dateDATEWeekly snapshot date
segmentVARCHAR(50)Customer segment in AbbVie Customer 360
is_activeBOOLEANWhether the customer is marked active
customer_interactions
ColumnTypeDescription
interaction_idPKINTInteraction row identifier
customer_idINTReferences customer_profiles.customer_id
interaction_dateDATEDate of interaction
channelVARCHAR(50)Interaction channel
interaction_countINTNumber of interactions recorded
Tablescustomer_profilescustomer_weekly_snapshotcustomer_interactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results