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: Nevin and Cynthia Hahn <lllacey_at_email.msn.com>
Date: Fri, 21 May 1999 23:25:28 -0600
Message-ID: <eHA5SLBp#GA.371@cpmsnbbsa02>


Hi RNK,

The having clause may help but you'll have to tweek the sum(quantity) to get the top 5:
SELECT PRODUCT_ID, PRODUCT_DESCRIPTION, SUM(QUANTITY) FROM ORDER_DETAILS
GROUP BY PRODUCT_ID, PRODUCT_DESCRIPTION ORDER BY 3
HAVING SUM(QUANTITY) > number
;

Also I don't think you need to group by both product_id and product_description,
the product_id is probably enough.

Nevin Hahn

Oracle Developer wrote in message <3745453A.52D5A30C_at_easynet.co.uk>...
>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.
Received on Sat May 22 1999 - 00:25:28 CDT

Original text of this message

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