查询 select 最大值

Query select max

我有这个table

+----+-----+---------+
| id | id2 | correct |
+----+-----+---------+
|  1 |   5 |       0 |
|  2 |   4 |       0 |
|  3 |   5 |       1 |
|  4 |   5 |       1 |
|  5 |   4 |       0 |
|  6 |   2 |       1 |
|  7 |   4 |       0 |
|  8 |   2 |       0 |
|  9 |   2 |       0 |
|  10|   5 |       1 |
|  11|   5 |       1 |
+----+-----+---------+

我需要 select id2 排序每个 id2 "correct" 答案“0”出现次数的最大值。 我举个例子。

id2: 2 - 出现了 3 次,3 次中有 2 次正确为“0”。
id2: 4 - 出现 3 次,3 次中有 3 次出现正确的“0”。
id2: 5 - 出现 5 次,5 次中有 1 次出现正确的“0”。

所以我想把id2“2”的id2排在前面,id2“5”排在最后一个。

对不起,我解释得不好,但我不知道该怎么做。

提前感谢您的宝贵时间

select id2
from mytable
where correct = 0
group by id2
order by count(*) desc

如果您还想包含没有正确答案的 ID:

select id2
from mytable
group by id2
order by sum(correct = 0) desc