oracle sql如何仅从返回结果中获取1行

oracle sql如何仅从返回结果中获取1行,sql,oracle,Sql,Oracle,如何改进此代码 select code,max(total) from (select code,count(*) from table_1 group by code) 上面的代码不起作用,因为我试图对查询的结果集执行MAX函数,但失败了 如果您只需要号码,则可以使用以下选项: select max(total) from ( select code, count(*) as total -- you forgot the column alias he

如何改进此代码

select code,max(total) from
(select code,count(*) from table_1 group by code) 

上面的代码不起作用,因为我试图对查询的结果集执行MAX函数,但失败了

如果您只需要号码,则可以使用以下选项:

select max(total) 
from (
     select code,
            count(*) as total -- you forgot the column alias here
     from table_1 
     group by code
) 
如果需要代码和编号,请使用以下命令:

with count_result as (
     select code,
            count(*) as total
     from table_1 
     group by code
) 
select code, 
       total
from count_result
where total = (select max(total) from count_result);

看看,目标到底是什么?
total
表1
中的一列,还是
count(*)的值?