Your question is SQL Window Function Ranking. 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.
Chargebee QA needs to validate invoice-ranking results in a billing report. Write a PostgreSQL query that ranks each active customer's paid invoices issued in June 2026 by invoice amount.
customers to invoices and include only active customers.paid_at value and an invoice_date from 2026-06-01 through 2026-06-30.RANK() so invoices with equal amounts receive the same rank. Sort final output by customer name, rank, then invoice number.| Column | Type | Description |
|---|---|---|
| customer_idPK | INTEGER | Unique Chargebee customer identifier. |
| customer_name | VARCHAR(100) | Display name of the customer. |
| is_active | BOOLEAN | Whether the customer account is active. |
| Column | Type | Description |
|---|---|---|
| invoice_idPK | INTEGER | Unique invoice identifier. |
| customer_id | INTEGER | Customer associated with the invoice. |
| invoice_number | VARCHAR(50) | Customer-facing Chargebee invoice number. |
| invoice_date | DATE | Date the invoice was issued. |
| amount | NUMERIC(12,2) | Invoice amount in the account currency. |
| paid_at | TIMESTAMP | Timestamp when the invoice was paid. |