+------------+---------+------------+--------------+------+
| dt | status | code | arena | cnt |
+------------+---------+------------+--------------+------+
| 2016-01-01 | failure | AB | kingdom1 | 2 |
| 2016-01-01 | success | AB | kingdom1 | 16 |
| 2016-01-01 | failure | CD | kingdom1 | 50 |
| 2016-01-01 | success | CD | kingdom1 | 662 |
| 2016-01-01 | failure | EF | kingdom1 | 131 |
| 2016-01-01 | success | EF | kingdom1 | 622 |
SQL查詢:獲取失敗百分比列
select DATE(created) as dt, status, code, arena,count(status) as cnt
from game_table
where some_condition
group by dt, code, status)
要求:
我需要找到code
,arena
明智的不良率,但我試圖將返回100全部失敗(baaaaad編碼器)。
+------------+---------+------------+--------------+------+
| dt | status | code | arena |failed|
+------------+---------+------------+--------------+------+
| 2016-01-01 | failure | AB | kingdom1 | 11.1 |
| 2016-01-01 | failure | CD | kingdom1 | 7.02 |
| 2016-01-01 | failure | EF | kingdom1 | 17.4 |
我想:
select dt, cnt/sum(cnt) as p, status, code, arena
from (
select DATE(created) as dt, status, code, arena,count(status) as cnt
from game_table
where some_condition
group by dt, code, status
) as inner_t
group by dt, code, status;
請顯示您的預期結果行。 –
@ThorstenKettner:新增 – NoobEditor
好。代碼GH不在結果中。王國2也不是。這是故意的嗎?如果是這樣,他們沒有被選中的共鳴是什麼?代碼AB應該有2/18 * 100 = 11.1的報價,對吧? –