代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MYSQL
】
统计时间分布脚本(mysql)
作者:
雅竹
/ 发布于
2016/12/19
/
894
-- 查询超时记录 select * from visit_record t where t.accesstime>to_date('2013-09-1','yyyy-MM-dd') and t.username is not null and t.result='成功' and t.totaltimecost>5000 and t.clientip <> '192.168.112.53' and t.clientip <> '192.168.112.200' and t.clientip <> '192.168.112.245' order by t.totaltimecost desc ; -- 导出日期范围内的日志信息(已xml格式导出为stat.xml,使用navicat工具导入进stat表) select t.username,t.accesstime,t.totaltimecost,t.accessurl from visit_record t where t.accesstime>to_date('2013-09-1','yyyy-MM-dd') and t.username is not null and t.result='成功' and t.clientip <> '192.168.112.53' and t.clientip <> '192.168.112.200' and t.clientip <> '192.168.112.245' and (t.accessurl='/newOA/m_flow/navPage.do' or t.accessurl='/newOA/m_commWorkflow/submitNode_2p0.do' or t.accessurl='/newOA/user/showDaiBanxiangJsp.do' or t.accessurl='/newOA/user/showDaiBanXiangList.do' ) order by t.totaltimecost desc ; -- 统计超时率(myql库中) select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF(t.TOTALTIMECOST>5000,t.TOTALTIMECOST,null)) as 超时次数 ,COUNT(IF(t.TOTALTIMECOST>5000,t.TOTALTIMECOST,null))/COUNT(t.ACCESSURL) as 超时率 ,ROUND(avg(t.TOTALTIMECOST)) as 平均耗时 ,max(t.TOTALTIMECOST) as 最大耗时 from stat t group by t.ACCESSURL order by 平均耗时 desc; -- 时间分布(异常统计) select t.ACCESSURL as url ,COUNT(IF(t.TOTALTIMECOST>5000 ,t.TOTALTIMECOST,null)) as 超时次数 ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '09:00:00' and '10:00:00' ,t.TOTALTIMECOST,null)) as '9' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '10:00:00' and '11:00:00' ,t.TOTALTIMECOST,null)) as '10' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '11:00:00' and '12:00:00' ,t.TOTALTIMECOST,null)) as '11' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '12:00:00' and '13:00:00' ,t.TOTALTIMECOST,null)) as '12' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '13:00:00' and '14:00:00' ,t.TOTALTIMECOST,null)) as '13' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '14:00:00' and '15:00:00' ,t.TOTALTIMECOST,null)) as '14' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '15:00:00' and '16:00:00' ,t.TOTALTIMECOST,null)) as '15' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '16:00:00' and '17:00:00' ,t.TOTALTIMECOST,null)) as '16' ,COUNT(IF(t.TOTALTIMECOST>5000 and time(t.ACCESSTIME) between '17:00:00' and '18:00:00' ,t.TOTALTIMECOST,null)) as '17' from stat t group by t.ACCESSURL with ROLLUP; select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( time(t.ACCESSTIME) between '09:00:00' and '10:00:00' ,t.TOTALTIMECOST,null)) as '9' ,COUNT(IF( time(t.ACCESSTIME) between '10:00:00' and '11:00:00' ,t.TOTALTIMECOST,null)) as '10' ,COUNT(IF( time(t.ACCESSTIME) between '11:00:00' and '12:00:00' ,t.TOTALTIMECOST,null)) as '11' ,COUNT(IF( time(t.ACCESSTIME) between '12:00:00' and '13:00:00' ,t.TOTALTIMECOST,null)) as '12' ,COUNT(IF( time(t.ACCESSTIME) between '13:00:00' and '14:00:00' ,t.TOTALTIMECOST,null)) as '13' ,COUNT(IF( time(t.ACCESSTIME) between '14:00:00' and '15:00:00' ,t.TOTALTIMECOST,null)) as '14' ,COUNT(IF( time(t.ACCESSTIME) between '15:00:00' and '16:00:00' ,t.TOTALTIMECOST,null)) as '15' ,COUNT(IF( time(t.ACCESSTIME) between '16:00:00' and '17:00:00' ,t.TOTALTIMECOST,null)) as '16' ,COUNT(IF( time(t.ACCESSTIME) between '17:00:00' and '18:00:00' ,t.TOTALTIMECOST,null)) as '17' from stat t group by t.ACCESSURL with ROLLUP; -- 日期分布(正常统计) select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=0 ,t.ACCESSTIME,null)) as '星期1' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=1 ,t.ACCESSTIME,null)) as '星期2' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=2 ,t.ACCESSTIME,null)) as '星期3' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=3 ,t.ACCESSTIME,null)) as '星期4' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=4 ,t.ACCESSTIME,null)) as '星期5' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=5 ,t.ACCESSTIME,null)) as '星期6' ,COUNT(IF( WEEKDAY(t.ACCESSTIME)=6 ,t.ACCESSTIME,null)) as '日' from stat t group by t.ACCESSURL select t.ACCESSURL as url ,COUNT(t.ACCESSURL) as 发生次数 ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=0 ,t.ACCESSTIME,null)) as '星期1' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=1 ,t.ACCESSTIME,null)) as '星期2' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=2 ,t.ACCESSTIME,null)) as '星期3' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=3 ,t.ACCESSTIME,null)) as '星期4' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=4 ,t.ACCESSTIME,null)) as '星期5' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=5 ,t.ACCESSTIME,null)) as '星期6' ,COUNT(IF( t.TOTALTIMECOST>5000 and WEEKDAY(t.ACCESSTIME)=6 ,t.ACCESSTIME,null)) as '日' from stat t group by t.ACCESSURL
试试其它关键字
同语言下
.
MySQL按日期分组统计(按天统计,按月统计)
.
mysql 获取某个库下面所有表的所有数据(
.
查看表当前自增值
.
查看碎片较多的表
.
查看数据表较大的表
.
查看非InnoDB引擎表
.
根据某一字段值按照某一特定符转化为列数据
.
按时间段分组查询当天小时内数据
.
mysql json 使用 类型 查询 函数
.
按天数据统计
可能有用的
.
MySQL按日期分组统计(按天统计,按月统计)
.
mysql 获取某个库下面所有表的所有数据(
.
查看表当前自增值
.
查看碎片较多的表
.
查看数据表较大的表
.
查看非InnoDB引擎表
.
根据某一字段值按照某一特定符转化为列数据
.
按时间段分组查询当天小时内数据
.
mysql json 使用 类型 查询 函数
.
按天数据统计
雅竹
贡献的其它代码
(
14
)
.
AJAX定时请求数据
.
Excel导出
.
利用JavaAPI来访问HDFS的文件与目录
.
根据分区查询数据
.
增量导入
.
统计时间分布脚本(mysql)
.
导入数据
.
获取页面高度和宽度(兼容 ie firefox chrome),获取鼠
.
网页中最常用的JS
.
改变文本框字体颜色
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3