我有以下 mysql 表
id status
------------
1 available
2 hold
3 available
4 so-hold
5 so-hold
6 hold
7 hold
8 available
当我在 STATUS
列上使用 GROUP BY
时,我得到以下结果:
count(id) status
---------------------
3 available
3 hold
2 so-hold
在status
列'hold'和'so-hold'属于同一类别,所以我需要按以下方式计数:
count(id) status
---------------------
3 available
5 hold
以下是我当前使用的 MySQL 查询:
SELECT count(id), status FROM `inventory_master` GROUP BY status
最佳答案
您可以使用CASE
语句
select
count(id),
case when status = 'so-hold'
then 'hold'
else status
end as status_col
from inventory_master
group by status_col
关于mysql - 使用 MYSQL 中的 GROUP BY 计算状态列上的 id 计数以及特定行计数的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27834203/