python - 我有 2 行,1 行用于时间戳,1 行用于状态“200 ok”和“未找到”,如何获得超过 1% 的错误
问题描述
2列用于时间戳,1列用于状态,我需要将每天的时间戳分组在一起,然后分别显示每天的一些错误,表名是一个日志。,我不需要它给我 1 个日期和 1 个错误,我需要它每天单独收集并告诉我堆栈中有多少错误!= '200 OK'
选择时间,最大(时间)作为错误(分别添加时间,而不是从日志中将天组合在一起,其中状态!= '200 OK' 按时间顺序按错误描述分组;和
select distinct time, count(status) as errors
from log having status != '200 OK' group by time order by errors desc;
example: i need it output like this:
2010-1-5 19:52:11 errors = 50
not like this
2010-1-5 19:52:11 errors = 1
2010-1-5 19:52:12 errors = 1
2010-1-5 19:52:13 errors = 1
2010-1-6 19:52:11 errors = 1
解决方案
给min(time)
。
要让它每天计数,您必须从时间字段中提取日期并按该日期分组。
例如,
select to_date(time,'dd-mm-yyyy'), count(status) as errors
from log having status != '200 OK' group by to_date(time,'dd-mm-yyyy') order by errors desc;
要获得错误百分比,请使用case
语句。
推荐阅读
- regex - 使用正则表达式捕获詹金斯管道中的数据
- php - 为来自特定 WooCommerce 产品类别的购物车商品设置最低数量
- amazon-s3 - s3 存储桶策略中的 InvalidCondition
- logic - 如何将逻辑语句转换为相反的语句?
- c - 转换 const 指针时是否保留 c 中的 const 限定符?
- arduino - 为自定义 arduino 更改 Wire 库的硬件 I2C 引脚
- reactjs - 如何在 React JS 应用程序中使用非本地文件执行人脸检测?
- ionic-framework - macOS 10.15 Beta:声称安装成功,但在设备上找不到应用程序。bundleId =
- vb.net - 无法解析两个日期以在 Visual Basic 中查询
- azure - 使用快速 Web 应用设置 Azure DevOps 源代码控制时出错