Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Member Claim Totals SQL

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

Your question is Rolling Member Claim Totals SQL. Start with the requirements and the two 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

Aetna's member analytics team needs monthly claim trend metrics for members. Write a PostgreSQL query that aggregates claim amounts by member and calendar month, then calculates both cumulative claim totals and a rolling three-month average.

Requirements

  1. Include claims from January 1, 2025 through June 30, 2025.
  2. Aggregate each member's claims by month, treating NULL claim amounts as zero.
  3. Calculate a running total ordered chronologically for each member.
  4. Calculate the average monthly claim amount for the current month and the preceding two calendar months using a window frame. Return one row for each member-month with at least one claim.

Schema

members
ColumnTypeDescription
member_idPKINTUnique member identifier
member_nameVARCHAR(100)Member's full name
plan_typeVARCHAR(30)Aetna health plan type
claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
member_idINTMember associated with the claim
claim_dateDATEDate the claim was submitted
claim_amountNUMERIC(12,2)Allowed claim amount
Tablesmembersclaims
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results