开发者

get max record in table

I have table like this:

table school

ID_School     name
--------------------
ACH001        jack
ACH001        gon
ACH001        fanny
ACH001        tony
ACH002        vera
ACH002        jessica
ACH003        rey
ACH003        tomy

I want output the max record ID_School开发者_如何学C in this table, and the output like this :

ID_School  count
-----------------
ACH001     4


In MS SQL:

select top 1 ID_School, count(*) IdCount
from school
group by ID_School
order by IdCount desc


This is it:

select ID_school,count(ID_school) as total from school group by names order by total desc limit 1;


For Oracle:

SELECT id_school, cnt
  FROM (SELECT id_school, count(*) cnt
          FROM school
         GROUP BY id_school
         ORDER BY cnt)
 WHERE ROWNUM = 1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜