Re: Top ten?

From: Jan Diesel <jwd_at_rivm.nl>
Date: Tue, 20 Apr 1993 08:11:11 GMT
Message-ID: <C5rw2o.66H_at_rivm.nl>


Michael Collier (sd345_at_city.ac.uk) wrote:
: Sorry if this is a FAQ.
:
: Suppose I am doing a group by query which returns lots of rows but I want the
: top ten (say).
:
: ie. select something, count(*)
: from a_table
: group by something
: order by something;
:
: I'd like the top ten something's, how do I do this?

Something like this should work (I'll leave the testing to you :-)

SELECT DISTINCT a.something
FROM a_table a
WHERE 10 < (SELECT COUNT(*)

	    FROM a_table b
	    WHERE a.something < b.something)

ORDER BY a.something;

:
: Thanks in advance. Michael.

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Jan Diesel                                       |          jwd_at_rivm.nl
Informatics Service Centre                       |  tel. ++31 30 742067
P.O.Box 1, 3720 BA  BILTHOVEN, the Netherlands   |  fax. ++31 30 282316
RIVM - National Institute of Public Health and Environmental Protection
Received on Tue Apr 20 1993 - 10:11:11 CEST

Original text of this message