Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SPOOKY SQL

Re: SPOOKY SQL

From: Dante <dnotari_at_my-dejanews.com>
Date: Tue, 25 May 1999 11:45:43 GMT
Message-ID: <7ie2h7$m96$1@nnrp1.deja.com>


Try

SELECT *
FROM ( SELECT PRODUCT_ID,

              PRODUCT_DESCRIPTION,
              SUM(QUANTITY) sum_qty
         FROM ORDER_DETAILS
     GROUP BY PRODUCT_ID, PRODUCT_DESCRIPTION
     ORDER BY 3 DESC)

WHERE ROWNUM <= 5;

Regards
Dante

In article <3745453A.52D5A30C_at_easynet.co.uk>,   Oracle Developer <rkamene_at_easynet.co.uk> wrote:
> Hello,
> I am trying trying to write a select statement that will return five
top
> selling products from a database table. The base table is the
> ORDER_DETAILS table which includes the product identity and the
quantity
> sold. So I want to
> SELECT PRODUCT_ID, PRODUCT_DESCRIPTION, SUM(QUANTITY)
> FROM ORDER_DETAILS
> GROUP BY PRODUCT_ID, PRODUCT_DESCRIPTION
> ORDER BY 3;
>
> The above will return all the products and quantity sold. How do I
> limit it to the top five best sellers.
> Thanks in advance.
> RNK.
>

--== Sent via Deja.com http://www.deja.com/ ==-- ---Share what you know. Learn what you don't.--- Received on Tue May 25 1999 - 06:45:43 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US