
mysql 分组统计失败率
问题:
如何在 mysql 中对表中的数据进行分组统计,计算指定字段的失败率?例如,对于一个具有以下结构的表:
create table `parse_monitoring` ( `id` int not null auto_increment, `track_source_id` int not null, `is_parsed` int not null, `parsed_at` timestamp not null default current_timestamp on update current_timestamp, primary key (`id`), key `index_parsed_at` (`parsed_at`) ) engine=innodb default charset=utf8mb4 collate=utf8mb4_0900_ai_ci;
其中:
给出这样的需求,统计每个 track_source_id 的解析失败率。
解答:
可以通过以下 sql 查询来实现:
SELECT track_source_id, 1 - SUM(is_parsed) / COUNT(*) FROM parse_monitoring GROUP BY track_source_id
以上就是如何使用 MySQL 统计每个监测对象的解析失败率?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号