Count the bank accounts in each income category, using these definitions:
-
low_income
: monthly income strictly less than 25000
-
medium_income
: monthly income in the inclusive range [25000, 60000]
-
high_income
: monthly income strictly greater than 60000
All three categories must appear in the result, with a count of 0 when a category has no accounts.
Input Table(s)
bank_accounts
| Column | Type | Meaning |
|---|
| account_id | int | Bank account identifier |
| monthly_income | int | Monthly income for the account |
Primary key: account_id. Each row holds the monthly income for one bank account.
Output Contract
-
Columns, in this order:
income_category
(text, one of
low_income
,
medium_income
,
high_income
) and
accounts_count
(integer).
-
Exactly three rows, one per category, including categories with a count of 0.
-
Order the rows
low_income
,
medium_income
,
high_income
.
income_category
is unique, so this order is fully determined.
-
No rounding.
Example
bank_accounts
| account_id | monthly_income |
|---|
| 1 | 15320 |
| 2 | 98210 |
| 3 | 45100 |
| 4 | 67250 |
| 5 | 32000 |
Expected result:
| income_category | accounts_count |
|---|
| low_income | 1 |
| medium_income | 2 |
| high_income | 2 |
Account 1 (15320) is the only low-income account. Accounts 3 (45100) and 5 (32000) fall in the medium range, and accounts 2 (98210) and 4 (67250) are above 60000.
A second input that tests the boundaries and an empty category:
| account_id | monthly_income |
|---|
| 10 | 25000 |
| 11 | 60000 |
| 12 | 60001 |
Expected result:
| income_category | accounts_count |
|---|
| low_income | 0 |
| medium_income | 2 |
| high_income | 1 |
25000 and 60000 are both inside the inclusive medium range, 60001 is high, and no account is below 25000, so low_income still appears with 0.
Constraints and Clarifications
-
account_id
is unique, so each account is counted once.
-
The boundaries 25000 and 60000 belong to
medium_income
.
-
An account whose
monthly_income
is NULL fits none of the three definitions and is not counted in any category.
-
If the table is empty, return the three categories, each with 0.