Re: SQL brainteaser..FUN!
Date: Mon, 20 Feb 1995 13:21:48 GMT
Message-ID: <1995Feb20.132148.29904_at_newton.ccs.tuns.ca>
In article <3i2gj9$mdr_at_shark.sb.grci.com> Walter Marek <wmarek_at_grci.com> writes:
>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?
>
>I am not a student trying to find someone to do their homework,
>just someone with enough knowlege of SQL to get themselves in
>trouble, but not enough to figure this one out.
>
>Please post appropriate responses to the newsgroup and mail
>a copy to wmarek_at_grci.com
>
>Have fun!
CREATE VIEW
V (AGE, CNTR)
AS
SELECT
AGE, COUNT (AGE)
FROM
T
GROUP BY
AGE;
SELECT
NAME, AGE
FROM
T
WHERE
AGE =
(SELECT
AGE
FROM
V
WHERE
CNTR =
(SELECT
MAX (CNTR)
FROM
V));
Received on Mon Feb 20 1995 - 14:21:48 CET