Re: SQL brainteaser..FUN!

From: Lawrence V. Rohrer <lrohrer_at_earthlink.net>
Date: Fri, 17 Feb 1995 20:27:20 -0800
Message-ID: <lrohrer-1702952027200001_at_lrohrer.earthlink.net>


In article <3i2gj9$mdr_at_shark.sb.grci.com>, Walter Marek <wmarek_at_grci.com> wrote:

> OK, here is the basic premise. There is a table with 2 columns:
> name char(20), age integer ... call it table T
>
> Here is some sample data :
>
> Tom,24
> Dick,40
> Harry,41
> Sally,24
> Mary,35
> Suzy,29
>
> We want to find out the AGE that occurs most frequently?
> What SQL query would return an answer of 24, not 2?

select age 'Most frequent age'
  from T
 group by age
 having count(*) = max(count(*))

I believe this will work but it hasn't been tested... Received on Sat Feb 18 1995 - 05:27:20 CET

Original text of this message