2015-09-25 59 views
0
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,而不是相應的值。選擇MAX()和相應的ID

我怎樣才能得到最大數量各自的id_university?

+0

住你實現什麼搶七策略(或沒有) – Drew

回答

2

使用ORDER BYLIMIT

SELECT COUNT(*) AS count, id_university 
FROM users 
WHERE status = 2 AND id_university > 0 
GROUP BY id_university 
ORDER BY count DESC 
LIMIT 1 
+0

宕哦,是的,就是這樣用。我是多麼愚蠢......非常感謝你的快速回答。 – Ekin