60. Top 2 Billing Admissions per Diagnosis

Hard Pinterest Window Functions
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
patients
10 cols
doctors
4 cols
admissions
7 cols
province_names
2 cols

Reference Solution

Expected SQL
WITH RankedCosts AS (SELECT diagnosis, admission_id, admission_cost, DENSE_RANK() OVER (PARTITION BY diagnosis ORDER BY admission_cost DESC) as rank FROM admissions) SELECT diagnosis, admission_id, admission_cost FROM RankedCosts WHERE rank <= 2;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.