Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Overlapping Policy Coverage SQL
00:00
5 left

Overlapping Policy Coverage SQL

HardSQL · PostgreSQL

Problem

Write a SQL query using window functions to identify overlapping insurance policy coverage periods for a single claimant.

Use the insurance_policies table and evaluate claimant 101. Coverage periods are inclusive, so a policy starting on the same date another policy ends is overlapping. Treat chained overlaps as one overlapping group.

Output

  1. One row per policy belonging to an overlapping group.
  2. Columns: claimant_id, overlap_group, policy_id, policy_number, coverage_start, coverage_end, and overlap_count.
  3. Exclude policies that do not overlap another policy, and order by coverage_start, coverage_end, then policy_id.

Schema

insurance_policies
ColumnTypeDescription
policy_idPKINTUnique identifier for the policy
claimant_idINTIdentifier of the claimant covered by the policy
policy_numberVARCHAR(30)External insurance policy reference
coverage_startDATEInclusive start date of coverage
coverage_endDATEInclusive end date of coverage
Tablesinsurance_policies
Interviewer

Your question is Overlapping Policy Coverage SQL. Start with the requirements and the one table 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.