选择MAX()和相应的id

时间:2015-09-25 23:27:19

标签: mysql

SELECT MAX(count),id_university FROM (
    SELECT COUNT(*) as count, id_university FROM `users` 
    where status = 2 AND id_university>0 
    GROUP BY id_university
)AS counts

目前上面的查询给了我id_university = 1而不是相应的值。

如何获得具有最大数量的相应id_university?

1 个答案:

答案 0 :(得分:2)

使用JViewportORDER BY

LIMIT