59. Identify Volatile Admission Cost Outliers

Hard ByteDance 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 PrevNext AS (SELECT patient_id, admission_id, admission_cost, LAG(admission_cost) OVER (PARTITION BY patient_id ORDER BY admission_date) as prev_cost, LEAD(admission_cost) OVER (PARTITION BY patient_id ORDER BY admission_date) as next_cost FROM admissions) SELECT patient_id, admission_id, admission_cost FROM PrevNext WHERE prev_cost IS NOT NULL AND next_cost IS NOT NULL AND admission_cost > 1.5 * prev_cost AND admission_cost > 1.5 * next_cost;
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.