G
Guest
I have a query to report the top 3 drugs used per client. My SQL is:
SELECT Clients.ClientName, OverallDrugsMonthly.[Drug Name],
OverallDrugsMonthly.[Net Rxs]
FROM OverallDrugsMonthly INNER JOIN Clients ON OverallDrugsMonthly.Client =
Clients.ClientID
WHERE (((OverallDrugsMonthly.[Drug Name]) In (Select Top 3 [Drug Name] From
OverallDrugsMonthly Where Client = Clients.ClientID Order By [Total Rx Users]
Desc)))
ORDER BY Clients.ClientName, OverallDrugsMonthly.[Net Rxs] DESC;
It works fine unless the number of Net Rxs is the same- ie if the net Rxs
for a specific client returns as 102, 46, 46, and 32 it reports all four
drugs instead of just the drugs associated with the Net Rxs count of 102, 46,
46. How do I make it stop reporting the top 4 rankings if 2 of the rankings
are the same?
Thanks for your help.
SELECT Clients.ClientName, OverallDrugsMonthly.[Drug Name],
OverallDrugsMonthly.[Net Rxs]
FROM OverallDrugsMonthly INNER JOIN Clients ON OverallDrugsMonthly.Client =
Clients.ClientID
WHERE (((OverallDrugsMonthly.[Drug Name]) In (Select Top 3 [Drug Name] From
OverallDrugsMonthly Where Client = Clients.ClientID Order By [Total Rx Users]
Desc)))
ORDER BY Clients.ClientName, OverallDrugsMonthly.[Net Rxs] DESC;
It works fine unless the number of Net Rxs is the same- ie if the net Rxs
for a specific client returns as 102, 46, 46, and 32 it reports all four
drugs instead of just the drugs associated with the Net Rxs count of 102, 46,
46. How do I make it stop reporting the top 4 rankings if 2 of the rankings
are the same?
Thanks for your help.