Write a SQL query to calculate monthly patient billing totals by department and rank the departments by revenue.
Use the departments and patient_billing tables. Include departments with billing records, rank departments independently within each month, and assign the same rank to tied totals.
billing_month, department_name, total_billing, and revenue_rank.| Column | Type | Description |
|---|---|---|
| department_idPK | INT | Unique department identifier |
| department_name | VARCHAR(100) | Keck Medicine department name |
| Column | Type | Description |
|---|---|---|
| billing_idPK | INT | Unique patient billing record identifier |
| department_id | INT | Department responsible for the billing record |
| billing_date | DATE | Date the patient billing activity was recorded |
| billed_amount | NUMERIC(12,2) | Amount billed for the patient service |