首页 > 解决方案 > 我有 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

标签: pythonsql

解决方案


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语句。


推荐阅读