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
SQL Timeline Overlap and Anomalies
00:00
5 left

SQL Timeline Overlap and Anomalies

HardSQL · PostgreSQL

Problem

Write a SQL query to identify overlapping transaction records and resolve anomalies in property ownership timelines.

Use the transaction and ownership timeline tables. Treat a NULL end date as an open-ended interval. Ownership records that overlap the next ownership period should be corrected so their end date is the day before the next period begins.

Output

  1. One row per overlapping transaction pair, including property_id, both transaction IDs, their date ranges, the number of affected ownership records, and corrected ownership end dates.
  2. Exclude transaction pairs from different properties and non-overlapping date ranges.
  3. Order by property_id, then the first transaction ID, then the second transaction ID.

Schema

transaction_records
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
property_idINTProperty associated with the transaction
transaction_startDATEBeginning of the transaction interval
transaction_endDATEEnd of the transaction interval, NULL means open-ended
transaction_typeVARCHAR(30)Transaction classification
statusVARCHAR(20)Transaction processing status
property_ownership
ColumnTypeDescription
ownership_idPKINTUnique ownership timeline identifier
property_idINTProperty associated with the ownership period
owner_nameVARCHAR(100)Owner during the period
valid_fromDATEStart of the ownership period
valid_toDATEEnd of the ownership period, NULL means current ownership
Tablestransaction_recordsproperty_ownership
Interviewer

Your question is SQL Timeline Overlap and Anomalies. Start with the requirements and the two 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.