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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

max function?

Status
Not open for further replies.

poolshark8or9

Technical User
Joined
Jan 20, 2005
Messages
4
Location
US
i am counting the total number of orders for each customer, but i only want it to return the top 100 customers, the customer with the most orders, down to the customer with the 100th most orders.
How can i do this?
Thanks in advance.
 
something like this:

SELECT A.CustID, A.CustName, A.CustTotal FROM Mytable A
WHERE A.CustTotal IN (SELECT TOP 100 CustTotal FROM Mytable B WHERE A.CustID=B.CustID ORDER BY CustTotal DESC)

-DNG
 
Sorry,
select top N
is not working in SYBASE
You will have to write it that way:

Code:
SET ROWCOUNT 100
SELECT A.CustID, A.CustName, A.CustTotal 
FROM Mytable A
ORDER BY CustTotal DESC

"A long life is when each day is full and every hour wide!"
(A Jewish Mentor)
M. [hourglass]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top