我正在尝试编写一个查询来选择选择的最高值。
SELECT especialidad,COUNT(*)
FROM medicos
GROUP BY especialidad
HAVING COUNT(*)=(SELECT MAX(COUNT(*))
FROM medicos
ORDER BY nombre,especialidad);
答案 0 :(得分:0)
由于order by
导致第二个max(count(*))
无关,因此您只需执行<{p}}
SELECT especialidad, COUNT(*)
FROM medicos
GROUP BY especialidad
ORDER BY COUNT(*) DESC
LIMIT 1
答案 1 :(得分:0)
您可以使用order by desc and limit 1
SELECT especialidad,COUNT(*) as total
FROM medicos
GROUP BY especialidad
order by total desc limit 1