我有一张桌子:
+--------+------------+---------+
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;
但我不知道如何获得每条记录的先前平均值列