做个笔记
SQLyog客户端访问MySQL服务器
统计数据:次数总数, 次数成功率,对象(obj)总数,对象(obj)成功率
要求:按时间排序和分组
sql语句如下:
SELECT
a.date AS `日期`,
a.total AS `总次数`,
a.objs AS `总对象数`,
ROUND(a.failed / a.total * 100, 2) AS `失败次数比率`,
ROUND(a.obj_failed/ a.objs * 100, 2) AS `对象失败率`
FROM
(SELECT
COUNT(1) AS `total`,
COUNT(DISTINCT(`obj_id`)) AS `objs`,
COUNT(IF(`description` LIKE '%object failed%', 1, NULL)) AS `failed`,
COUNT(DISTINCT(IF(`description` LIKE '%object failed%', `obj_id`, NULL))) AS `obj_failed`,
DATE(`created_at`) AS `date`
FROM `mydb.my_table` WHERE `created_at` > '2016-03-07 0'
GROUP BY `date`
ORDER BY `date` DESC)
AS a