需求:找出NAME列值最多的对应ID的最大值
SQL> select * from key;
ID NAME
---------- ----------
1 a
2 a
3 a
2 b
3 b
4 a
99 a
10000 b
999 a
100 a
已选择10行。
SQL>
SQL> select max(id)
2 from key
3 where name = (select name
4 from (select name, count(*)
5 from key
6 group by name
7 order by count(*) desc)
8 where rownum < 2);
MAX(ID)
----------
999