how do i improved this code.
select code,max(total) from
(select code,count(*) from table_1 group by code)
The above code,not working because I try to do MAX function onto the result set from query,but failed.
how do i improved this code.
select code,max(total) from
(select code,count(*) from table_1 group by code)
The above code,not working because I try to do MAX function onto the result set from query,but failed.
If you only want the number, then you can use this:
select max(total)
from (
select code,
count(*) as total -- you forgot the column alias here
from table_1
group by code
)
If you want the code and the number, use the following:
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);