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
Get started
Top Billing Providers Query
00:00
5 left

Top Billing Providers Query

MediumSQL · PostgreSQL

Problem

Write a query to find the top three highest-billing insurance providers for a specific diagnostic test over the last quarter at Natera.

Use the Panorama test and the previous calendar quarter relative to the query date. Exclude voided claims and records outside the quarter.

Output

  1. One row per selected insurance provider with provider_id, provider_name, total_billed, and billing_rank.
  2. Return exactly the three highest-billing providers, ordered by billing_rank, then provider_name.

Output details

  • Treat DATE '2026-07-01' as today's date.
  • Use an inclusive quarter start and an exclusive quarter end.
  • Rank ties by provider_name ascending after total_billed descending.
  • Place NULL total_billed values after non-NULL values when ranking.
  • Exclude claims whose claim_status is NULL, as well as claims with status VOID.
  • Return total_billed as the unrounded sum, preserving its numeric precision.

Schema

insurance_providers
ColumnTypeDescription
provider_idPKINTUnique insurance provider identifier
provider_nameVARCHAR(100)Insurance provider name
payer_typeVARCHAR(30)Provider classification
diagnostic_tests
ColumnTypeDescription
test_idPKINTUnique diagnostic test identifier
test_codeVARCHAR(30)Diagnostic test code
test_nameVARCHAR(100)Diagnostic test name
test_billing
ColumnTypeDescription
billing_idPKINTUnique billing record identifier
provider_idINTReferenced insurance provider
test_idINTReferenced diagnostic test
billed_amountDECIMAL(12,2)Amount billed for the claim
billed_atDATEDate the billing record was submitted
claim_statusVARCHAR(20)Claim processing status
Tablesinsurance_providersdiagnostic_teststest_billing
Interviewer

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

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.