我有一张table:
+--------+------------+---------+
id | day | status |
+--------+------------+---------+
1 | 2018-01-01 | FAIL |
2 | 2018-01-02 | SUCCESS |
3 | 2018-01-02 | SUCCESS |
4 | 2018-01-02 | SUCCESS |
5 | 2018-01-03 | SUCCESS |
6 | 2018-01-03 | FAIL |
7 | 2018-01-03 | FAIL |
8 | 2018-01-04 | SUCCESS |
9 | 2018-01-04 | SUCCESS |
10 | 2018-01-05 | SUCCESS |
11 | 2018-01-05 | SUCCESS |
12 | 2018-01-05 | SUCCESS |
+--------+------------+---------+
我必须创建一个包含下一个信息的查询:
每天的失败次数
每天的成功计数
成功+失败每天数
每天成功状态的百分比
从第四个记录开始,每天获得前三天成功百分比的平均值
我创建了一个查询来获取1-4个点的信息:
SELECT day, fails, success, fails + success AS total,
(success*100/(success+fails)) AS success_percent
FROM (
SELECT day,
SUM(IF(status='FAIL',1,0)) AS fails,
SUM(IF(status='SUCCESS',1,0)) AS success
FROM statuses
GROUP BY day) AS inner_query;
但我不知道如何获得每个记录的前一个平均值列
暂无答案!
目前还没有任何答案,快来回答吧!