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

ranking and limiting query records 1

Status
Not open for further replies.

cochise

Technical User
Mar 27, 2001
171
US
I have a simple query that returns supplier and spend data; however, it returns thousands of records. I want to sort descending on spend value, and return only the top 50 records. How can I create a field that ranks by top spend?
I appreciate the help.

Here is my current SQL:

SELECT [Raw OPW SMD Dump].[Supplier Name], Sum([Raw OPW SMD Dump].[OPW Amount]) AS [OPW Total], [Raw OPW SMD Dump].Period
FROM [Raw OPW SMD Dump]
GROUP BY [Raw OPW SMD Dump].[Supplier Name], [Raw OPW SMD Dump].Period
HAVING ((([Raw OPW SMD Dump].Period)="2003"))
ORDER BY Sum([Raw OPW SMD Dump].[OPW Amount]) DESC;
 
Try this:

SELECT TOP 50 [Raw OPW SMD Dump].[Supplier Name], Sum([Raw OPW SMD Dump].[OPW Amount]) AS [OPW Total], [Raw OPW SMD Dump].Period
FROM [Raw OPW SMD Dump]
GROUP BY [Raw OPW SMD Dump].[Supplier Name], [Raw OPW SMD Dump].Period
HAVING ((([Raw OPW SMD Dump].Period)="2003"))
ORDER BY Sum([Raw OPW SMD Dump].[OPW Amount]) DESC;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top