gpt4 book ai didi

MySQL:根据字段名称计算行数

转载 作者:行者123 更新时间:2023-12-01 00:28:51 25 4
gpt4 key购买 nike

我的 MySql 数据库表结构是:

id | status
1 | Open
2 | Open
3 | Closed
4 | Open
5 | Closed

我想计算打开和关闭行的总数。

Status | Total
Open | 3
Closed | 2

我用过

SELECT count(distinct status) as Total FROM my_tbl

但它返回

Total
2

最佳答案


SELECT status,
COUNT(id) AS `total`
FROM your_table
GROUP BY status
ORDER BY total DESC

关于MySQL:根据字段名称计算行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9108872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com