Choosing bottom 3 for multiple entries

Astello

Registered User.
Local time
Yesterday, 20:43
Joined
Oct 6, 2006
Messages
29
I have a database with information on carriers, lanes, and prices.
I need to choose the cheapest 3 carriers for each lane.
The lanes are either 3-digit zip code to 3-digit zip code or state to state
(410-300 or CA-GA, etc.)
So for each of these lanes, I need to find the 3 cheapest carriers all
in one query.
So the resulting table should look like:

Lane Carrier Price
..........
TN-FL Schneider $50
TN-FL JB Hunt $66
TN-FL Dart $78
646-303 JB Hunt $77
etc.....

Except of course in columns :) Any ideas on how to do this? Thanks in advance!
 
How about the MIN aggregate under the Totals button. Have you done a Totals query before?
 
Here's what I did instead:

SELECT T.Lane, T.Carrier, T.Price, (SELECT COUNT(*)
FROM [AllRates] T1
WHERE T1.Lane = T.Lane
AND T1.Price <= T.Price) AS Rank
FROM AllRates AS T
WHERE ((((SELECT COUNT(*)
FROM [AllRates] T1
WHERE T1.Lane = T.Lane
AND T1.Price <= T.Price))<=3))
ORDER BY T.Lane, T.Price;
 

Users who are viewing this thread

Back
Top Bottom