Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Rolling 30-Day Claims Average

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

Your question is SQL Rolling 30-Day Claims Average. 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

Blue Cross and Blue Shield of Kansas needs a daily claims-volume trend for its active plan products. Write a PostgreSQL query that calculates the trailing 30-calendar-day average number of finalized claims for each active plan.

Requirements

  1. Count claims with status PAID or DENIED; exclude PENDED and VOID claims.
  2. Include calendar dates with zero claims so the average represents 30 calendar days rather than only days containing claims.
  3. Calculate the rolling average separately for each active plan using the current date and preceding 29 dates.
  4. Return results for January 31, 2025 through February 5, 2025, ordered by plan code and date. Round the average to four decimal places.

Schema

plan_products
ColumnTypeDescription
plan_codePKVARCHAR(20)Unique plan product identifier
plan_nameVARCHAR(100)Plan product display name
active_fromDATEProduct activation date
active_toDATEProduct deactivation date
claims
ColumnTypeDescription
claim_idPKINTUnique claim identifier
plan_codeVARCHAR(20)Associated plan product code
service_dateDATEDate of service
statusVARCHAR(20)Claim adjudication status
Tablesplan_productsclaims
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results