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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Claims Reporting Data Modeling
00:00
5 left

Claims Reporting Data Modeling

HardSQL · PostgreSQL

Problem

How do you design a data model for a complex MetLife insurance claims reporting system to optimize both write performance and read query speeds?

For the supplied relational model, write a PostgreSQL query that produces a monthly claims report for claims opened during the first quarter of 2024. The report must use the latest available claim status and include payment and closure metrics.

Output

  1. One row per line of business and claim month, ordered by line of business and month.
  2. Return line_of_business, claim_month, claim_count, total_paid, average_days_to_close, prior_month_claim_count, and cumulative_paid.
  3. Include claims without events or payments, treating missing payments as zero. Claims outside the quarter are excluded.

Output details

  • Order both line_of_business and claim_month ascending.
  • Treat the first-quarter bounds as inclusive 2024-01-01 and exclusive 2024-04-01.
  • Break latest-event ties by descending event_ts, then descending event_id.
  • Calculate closure days only for claims whose latest status is CLOSED, using date difference from opened_at to event_ts, and round the average to 2 decimals.
  • Return NULL for average_days_to_close when no latest status is CLOSED.
  • Compute prior-month counts and cumulative payments over existing claim months only, leaving the first available month’s prior count NULL.

Schema

policies
ColumnTypeDescription
policy_idPKINTUnique policy identifier
policy_numberVARCHAR(20)Business policy number
line_of_businessVARCHAR(40)Insurance product line
claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
policy_idINTPolicy associated with the claim
claim_typeVARCHAR(30)Claim classification
opened_atDATEDate the claim was opened
claim_events
ColumnTypeDescription
event_idPKINTUnique event identifier
claim_idINTClaim associated with the event
statusVARCHAR(20)Status recorded by the event
event_tsTIMESTAMPTimestamp of the status event
claim_payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
claim_idINTClaim associated with the payment
amountNUMERIC(12,2)Payment amount
Tablespoliciesclaimsclaim_eventsclaim_payments
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the four tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.