Search notes:

Oracle aggregate functions: STATS_MODE

stats_mode returns the value that occurs the most.
create table tq84_stats_mode (
  val number
);

insert into tq84_stats_mode values (     1);
insert into tq84_stats_mode values (     2);
insert into tq84_stats_mode values (     3);
insert into tq84_stats_mode values (    42);
insert into tq84_stats_mode values (     2);
insert into tq84_stats_mode values (   999);
insert into tq84_stats_mode values (    42);
insert into tq84_stats_mode values (    42);
insert into tq84_stats_mode values (     3);


-- Which value occurs the most?
select
  stats_mode(val)
from
  tq84_stats_mode;
-- 
-- STATS_MODE(VAL)
-- ---------------
--              42

select
  count(*),
  val
from
  tq84_stats_mode
group by
  val
order by count(*) desc
fetch first row only;
-- 
--   COUNT(*)        VAL
-- ---------- ----------
--          3         42

drop table tq84_stats_mode;
Github repository Oracle-Patterns, path: /SQL/select/aggregate/stats_mode.sql

See also

aggregate function

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740465138, '52.14.127.77', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/select/aggregate/stats_mode(80): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78