home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.oracle
- Path: sparky!uunet!stanford.edu!eos!aio!casivils
- From: casivils@lescsse.jsc.nasa.gov (craig sivils)
- Subject: Re: Explain THIS, please!
- Message-ID: <casivils.725585665@node_508ba>
- Sender: news@aio.jsc.nasa.gov (USENET News System)
- Organization: Lockheed Engineering and Sciences
- References: <1gtd91INN7ln@ef2007.efhd.ford.com> <1992Dec22.163411.557@hhcs.gov.au> <1992Dec23.150326.560@hhcs.gov.au>
- Date: 28 Dec 92 23:34:25 GMT
- Lines: 32
-
- Given the following table
-
- SQL> desc test
- Name Null? Type
- ------------------------------- -------- ----
- PART CHAR(10)
- COUNT
-
- The following select statement returns the top X groups
-
- SELECT PART
- FROM TEST TOPTEN
- GROUP BY PART
- HAVING &1>(SELECT COUNT(DISTINCT PART) FROM TEST
- WHERE PART IN ( SELECT UNIQUE(PART)
- FROM TEST
- GROUP BY PART
- HAVING ((SUM(COUNT)>(SELECT SUM(COUNT) FROM TEST
- WHERE PART = TOPTEN.PART
- GROUP BY PART ) )OR
- (SUM(COUNT)=(SELECT SUM(COUNT) FROM TEST
- WHERE PART = TOPTEN.PART
- GROUP BY PART ) AND
- PART > TOPTEN.PART ) ) ) )
- ORDER BY SUM(COUNT),PART
-
-
- Craig
-
- I realize that this could be optimized quite a bit, most noteably, the inner
- most subquerys for the sum of the count is redundant, but hey, redundant is
- a step up from impossible.
-