bo_reception_process_record表中有process_id,attend,status,people_num字段,现在想根据process_id筛选出来的数据,获取到attend = 2和attend = 1和status = 10和status = 20不同状态下,计算people_num的总数,请帮我写一个sql
时间: 2024-03-08 14:49:01 浏览: 59
查询一个数据库中所有表中的数据量、表中的数据是否有状态区分字段,如果有根据不同的状态区分字段计算表中有效信息、无效信息的数量
好的,以下是根据您的要求写的 SQL 语句:
```
SELECT
SUM(IF(attend = 1 AND status = 10, people_num, 0)) AS attend_1_status_10_num,
SUM(IF(attend = 1 AND status = 20, people_num, 0)) AS attend_1_status_20_num,
SUM(IF(attend = 2 AND status = 10, people_num, 0)) AS attend_2_status_10_num,
SUM(IF(attend = 2 AND status = 20, people_num, 0)) AS attend_2_status_20_num
FROM
bo_reception_process_record
WHERE
process_id = 'your_process_id';
```
以上 SQL 语句中,使用了 `IF` 函数对 `people_num` 进行了分类求和,分别计算了 `attend = 1` 且 `status = 10`,`attend = 1` 且 `status = 20`,`attend = 2` 且 `status = 10`,`attend = 2` 且 `status = 20` 四种情况下的总人数。您只需要将 `your_process_id` 替换成您想要筛选的 `process_id` 即可。
阅读全文