Given a table Accounts with bank account information, write a SQL solution to calculate the number of bank accounts for each salary category.
Salary Categories:
- "Low Salary": All salaries strictly less than $20,000
- "Average Salary": All salaries in the inclusive range [$20,000, $50,000]
- "High Salary": All salaries strictly greater than $50,000
Requirements:
- The result table must contain all three categories
- If there are no accounts in a category, return 0
- Return the result in any order
Table Schema
| Column Name | Type | Description |
|---|---|---|
account_id
PK
|
int | Primary key - unique account identifier |
income
|
int | Monthly income for the bank account |
Input & Output
| account_id | income |
|---|---|
| 3 | 108939 |
| 2 | 12747 |
| 8 | 87709 |
| 6 | 91796 |
| category | accounts_count |
|---|---|
| Low Salary | 1 |
| Average Salary | 0 |
| High Salary | 3 |
Account 2 has income $12,747 which is < $20,000 (Low Salary). Accounts 3, 8, and 6 have incomes > $50,000 (High Salary). No accounts fall in the Average Salary range, so it shows 0.
| account_id | income |
|---|---|
| 1 | 15000 |
| 2 | 25000 |
| 3 | 35000 |
| 4 | 75000 |
| category | accounts_count |
|---|---|
| Low Salary | 1 |
| Average Salary | 2 |
| High Salary | 1 |
Account 1 ($15,000) is Low Salary. Accounts 2 and 3 ($25,000 and $35,000) are Average Salary. Account 4 ($75,000) is High Salary. All three categories have at least one account.
| account_id | income |
|---|---|
| 1 | 20000 |
| 2 | 50000 |
| 3 | 19999 |
| 4 | 50001 |
| category | accounts_count |
|---|---|
| Low Salary | 1 |
| Average Salary | 2 |
| High Salary | 1 |
Testing boundary conditions: $19,999 is Low Salary (< 20000), $20,000 and $50,000 are Average Salary (inclusive range), and $50,001 is High Salary (> 50000).
Constraints
-
1 ≤ account_id ≤ 10^6 -
0 ≤ income ≤ 10^6 - All account_id values are unique