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 counts 1

Status
Not open for further replies.

Eddyoftheyear

Technical User
Aug 11, 2010
57
US
Hi All,

I need to pull the top six provider who has the highest number of apppointments from each depts in the following statement:

SELECT Query2.Depts, Query2.[Full Name], Query2.CountOfAppointment
FROM Query2;
 
What about this ?
Code:
SELECT A.Depts, A.[Full Name], A.CountOfAppointment
FROM Query2 A INNER Query2 B ON A.Depts=B.Depts AND A.CountOfAppointment<=B.CountOfAppointment
GROUP BY A.Depts, A.[Full Name], A.CountOfAppointment
HAVING COUNT(*)<=6
ORDER BY 1, 3 DESC

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry for the typo:
Code:
SELECT A.Depts, A.[Full Name], A.CountOfAppointment
FROM Query2 A INNER [!]JOIN[/!] Query2 B ON A.Depts=B.Depts AND A.CountOfAppointment<=B.CountOfAppointment
GROUP BY A.Depts, A.[Full Name], A.CountOfAppointment
HAVING COUNT(*)<=6
ORDER BY 1, 3 DESC

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top