Need Highest Value In Query

G

GeeseWatcher

I am trying to build a query that will return the highest value based on the
city, state, cost.

My query has over 300,000 records with Hub City, Hub State, Destination,
Rate, Fuel, Trucker, and Total Costs. For each Hub and Destination there
could be more than one cost depending on the trucker that is used. I need to
find a way to filter for one value (Hub, Destination, Cost) using the highest
cost regardless of the trucker.

I apologize if this isn't very clear, but any help would be appreciated.
 
R

Ryan

Why not just make a query with those 3 fields (Hub, Destination,Cost) and
sort Desending on the Cost?
 
G

GeeseWatcher

We did try that. However, for each location there can be more than one rate.
Sorting the rates descending isn't the issue, we just need to see ONE rate
for all the locations.
 
K

KARL DEWEY

It can can be done with one query if you know subqueries but here it is using
two and table named GeeseWatcher --

QRY GeeseWatcher_1 --
SELECT GeeseWatcher.City, GeeseWatcher.State, GeeseWatcher.Destination,
Max(GeeseWatcher.[Total Costs]) AS [MaxOfTotal Costs]
FROM GeeseWatcher
GROUP BY GeeseWatcher.City, GeeseWatcher.State, GeeseWatcher.Destination;

SELECT GeeseWatcher.*
FROM GeeseWatcher INNER JOIN GeeseWatcher_1 ON (GeeseWatcher.[Total Costs] =
GeeseWatcher_1.[MaxOfTotal Costs]) AND (GeeseWatcher.Destination =
GeeseWatcher_1.Destination) AND (GeeseWatcher.State = GeeseWatcher_1.State)
AND (GeeseWatcher.City = GeeseWatcher_1.City);
 
G

GeeseWatcher

Thanks Karl...that worked great!

KARL DEWEY said:
It can can be done with one query if you know subqueries but here it is using
two and table named GeeseWatcher --

QRY GeeseWatcher_1 --
SELECT GeeseWatcher.City, GeeseWatcher.State, GeeseWatcher.Destination,
Max(GeeseWatcher.[Total Costs]) AS [MaxOfTotal Costs]
FROM GeeseWatcher
GROUP BY GeeseWatcher.City, GeeseWatcher.State, GeeseWatcher.Destination;

SELECT GeeseWatcher.*
FROM GeeseWatcher INNER JOIN GeeseWatcher_1 ON (GeeseWatcher.[Total Costs] =
GeeseWatcher_1.[MaxOfTotal Costs]) AND (GeeseWatcher.Destination =
GeeseWatcher_1.Destination) AND (GeeseWatcher.State = GeeseWatcher_1.State)
AND (GeeseWatcher.City = GeeseWatcher_1.City);

--
KARL DEWEY
Build a little - Test a little


GeeseWatcher said:
We did try that. However, for each location there can be more than one rate.
Sorting the rates descending isn't the issue, we just need to see ONE rate
for all the locations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top