Interview Questions/SQL/Count Salary Categories

Count Salary Categories

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Description

You are given an Accounts table containing account IDs and their income. Classify each account into one of three salary categories: - 'Low Salary': income strictly less than 20000 - 'Average Salary': income between 20000 and 50000 inclusive - 'High Salary': income strictly greater than 50000 Write a SQL query to report the number of accounts in each category. If a category has no accounts, report 0. Return all three categories in the result - even if their count is zero.

Database Schema

Accounts

Column NameExample Value
account_id3
income108939

Example

Accounts

account_idincome
3108939
212747
887709
691796

Output

categoryaccounts_count
Low Salary1
Average Salary0
High Salary3

Explanation:

Account 2 earns 12747 → Low Salary. Accounts 3, 6, 8 earn above 50000 → High Salary. No account falls in Average Salary range.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

SQL Editor
Loading...

Accounts

account_idincome
3108939
212747
887709
691796

Output

categoryaccounts_count
Low Salary1
Average Salary0
High Salary3