# 1907.(Medium)Count Salary Categories

表: Accounts

```
+-------------+------+
| 列名        | 类型  |
+-------------+------+
| account_id  | int  |
| income      | int  |
+-------------+------+
account_id 是这个表的主键。
每一行都包含一个银行帐户的月收入的信息。
```

写出一个 SQL 查询，来报告每个工资类别的银行账户数量。 工资类别如下：

“低薪”：所有工资严格低于20000美元。

“中等薪水”：包含范围内的所有工资 \[$20000, $50000]。

“高薪”：所有工资严格大于50000美元。

结果表必须包含所有三个类别。 如果某个类别中没有帐户，则报告 0。

按任意顺序返回结果表。

查询结果格式如下示例：

```
Accounts 表:
+------------+--------+
| account_id | income |
+------------+--------+
| 3          | 108939 |
| 2          | 12747  |
| 8          | 87709  |
| 6          | 91796  |
+------------+--------+

Result 表:
+----------------+----------------+
| category       | accounts_count |
+----------------+----------------+
| Low Salary     | 1              |
| Average Salary | 0              |
| High Salary    | 3              |
+----------------+----------------+

低薪: 数量为 2.
中等薪水: 没有.
高薪: 有三个账户，他们是 3, 6和 8.
```

来源：力扣（LeetCode）

链接：<https://leetcode-cn.com/problems/count-salary-categories>

著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。

## Solution

```sql
SELECT 'Low Salary' category,sum(if(income<20000,1,0)) accounts_count FROM accounts
UNION 
SELECT 'Average Salary' category,sum(if(income between 20000 and 50000,1,0)) accounts_count FROM accounts
UNION 
SELECT 'High Salary' category,sum(if(income>50000,1,0)) accounts_count FROM accounts
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zqt0.gitbook.io/leetcode/sql/1907.count-salary-categories.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
