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
Schema for Historical Statuses
00:00
5 left

Schema for Historical Statuses

HardSQL · PostgreSQL

Problem

How would you design a relational schema to track historical changes in customer account statuses?

Define a normalized structure that preserves every status change and supports reconstructing each account's status over time. Write a PostgreSQL query using the provided structure to return the resulting status intervals.

Output

  1. One row per recorded account status interval
  2. Columns: account_id, customer_name, status_code, status_name, effective_from, effective_to, duration_days, and changed_by
  3. Include the current interval with a NULL end date
  4. Order by account_id, then effective_from ascending

Schema

customers
ColumnTypeDescription
customer_idPKBIGINTUnique customer identifier
customer_nameVARCHAR(150)Customer's display name
accounts
ColumnTypeDescription
account_idPKBIGINTUnique account identifier
customer_idBIGINTOwner of the account
account_typeVARCHAR(40)Account product type
opened_atDATEDate the account was opened
account_statuses
ColumnTypeDescription
status_codePKVARCHAR(30)Controlled status code
status_nameVARCHAR(100)Human-readable status name
account_status_history
ColumnTypeDescription
history_idPKBIGINTUnique status event identifier
account_idBIGINTAccount whose status changed
status_codeVARCHAR(30)Status assigned by the event
effective_atDATEDate the status became effective
changed_byVARCHAR(100)User or system that made the change
reasonVARCHAR(255)Reason recorded for the status change
Tablescustomersaccountsaccount_statusesaccount_status_history
Interviewer

Your question is Schema for Historical Statuses. 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.