Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 10 and Bottom 10 1

Status
Not open for further replies.

ADB1

Programmer
Aug 24, 2001
235
GB
Can anybody tell me the sql for getting the top 10 and WQorst ten selling products if I had the following basic sql....

Select
Product_id,
Net_Sales,
Rank(Net_Sales)
From Product

I can get the rank value but am not sure how to get the top 10 and bottom 10.

Thanks in advance.

A.
 
Top 10:

...
Rank(Net_Sales DESC) as NetRank
...
Qualify RANK(NetRank) <= 10

Bottom 10:
...
Rank(Net_Sales ASC) as NetRank
...
Qualify RANK(NetRank) <= 10

FYI:
Rank(Net_sales) = Rank(Net_Sales DESC)
so DESC is default in ranks (top x)
 
Thanks for the help. One quick question, where would you put the QUALIFY statement in your SQL? In the Where?

Thanks.

A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top