获取表中的最大记录

问题描述

| 我有这样的表: 餐桌学校
ID_School     name
--------------------
ACH001        jack
ACH001        gon
ACH001        fanny
ACH001        tony
ACH002        vera
ACH002        jessica
ACH003        rey
ACH003        tomy
我想在此表中输出最大记录ID_School,并输出如下所示:
ID_School  count
-----------------
ACH001     4
    

解决方法

在MS SQL中:
select top 1 ID_School,count(*) IdCount
from school
group by ID_School
order by IdCount desc
    ,就是这个:
select ID_school,count(ID_school) as total from school group by names order by total desc limit 1;
    ,对于Oracle:
SELECT id_school,cnt
  FROM (SELECT id_school,count(*) cnt
          FROM school
         GROUP BY id_school
         ORDER BY cnt)
 WHERE ROWNUM = 1;