我有以下查询:
SELECT q.category_id as Category_id , COUNT(q.question_id) as count
from questions as q
INNER JOIN interestingQuestion as i using (question_id)
group by q.category_id
这给了我以下结果 - 正如我根据表中的数据所需要的那样:
Category_id Count
5 1
6 3
现在我需要找到具有最高计数器的 category_id,所以我做了以下查询:
SELECT t.Category_id, MAX(t.Count)
from(
SELECT q.category_id as Category_id , COUNT(q.question_id) as count
from questions as q INNER JOIN interestingQuestion as i using (question_id)
group by q.category_id
)as t
我得到的结果是:
category_id MAX(t.count)
5 3
这是一个混淆的结果,它正在找到最大计数器,但它给了我一个错误的 category_id
为什么会这样?我该如何解决?