Re: [sqlite] Re: Calculating the mode

2005-11-21 Thread Kurt Welgehausen
> select salary, count(*) occurs from payroll
> group by salary having occurs =
>   (select count(*) c from payroll group by salary
>order by c desc limit)

OR

select salary, count(*) from payroll group by salary
having count(*) = (select max(cnt) from
   (select count(*) cnt from payroll group by salary))

Regards


[sqlite] Re: Calculating the mode

2005-11-21 Thread Igor Tandetnik

[EMAIL PROTECTED] wrote:

"Igor Tandetnik" <[EMAIL PROTECTED]> wrote:

Tim Martin wrote:

Does anyone have any working solutions for calculating the mode of a
set of values in SQLite?


I'm not exactly sure what  "mode" is. From your examples, it seems
you want to get an element that occurs most often. This should do it:

select salary, count(*) occurs
from payroll
group by salary
having occurs=
  (select count(*) c from payroll group by salary order by c desc
limit 1)



Or how about:

  select salary, count(*) frequency
from payroll
   group by salary
   order by frequency
   limit 1;


This does not quite do the right thing if there are two or more values 
with equal frequency.


Igor Tandetnik 



[sqlite] Re: Calculating the mode

2005-11-21 Thread Igor Tandetnik

Tim Martin wrote:

Does anyone have any working solutions for calculating the mode of a
set of values in SQLite?


I'm not exactly sure what  "mode" is. From your examples, it seems you 
want to get an element that occurs most often. This should do it:


select salary, count(*) occurs
from payroll
group by salary
having occurs=
 (select count(*) c from payroll group by salary order by c desc limit 
1)


Igor Tandetnik