SELECT CASE WHEN r.RECEIVE_FLAG = 1 THEN '进行中' WHEN r.CANCEL_FLAG = 1 THEN '已取消' WHEN r.REMOVE_FLAG = 1 THEN '已解除' ELSE '待接收' END AS "状态", COUNT(*) AS "reportCount" FROM FAULT_REPORT r怎么按状态分组并统计数量 在oracle中实现
时间: 2024-03-05 09:48:53 浏览: 48
您可以在该 SQL 查询语句的末尾添加 GROUP BY 子句,并指定“状态”字段,以按状态分组并统计数量。具体语句如下所示:
```
SELECT
CASE
WHEN r.RECEIVE_FLAG = 1 THEN '进行中'
WHEN r.CANCEL_FLAG = 1 THEN '已取消'
WHEN r.REMOVE_FLAG = 1 THEN '已解除'
ELSE '待接收'
END AS "状态",
COUNT(*) AS "reportCount"
FROM
FAULT_REPORT r
GROUP BY
CASE
WHEN r.RECEIVE_FLAG = 1 THEN '进行中'
WHEN r.CANCEL_FLAG = 1 THEN '已取消'
WHEN r.REMOVE_FLAG = 1 THEN '已解除'
ELSE '待接收'
END;
```
以上查询语句会按照“状态”字段进行分组,并统计每个状态的数量。
阅读全文