in reply to Help with manipulating data from a database??
If I understand correctly, you want the minimum distance (along with the stop_reference) for each service_id. If you didn't need the stop_reference, you could just do a GROUP BY:
-- not what you want SELECT service_id, min(distance) FROM table GROUP BY service_id;
But then you lose the stop_reference information, because you've "grouped" that away.
So what I'd probably do is use ORDER BY:
SELECT stop_reference, service_id, distance FROM table ORDER BY service_id, distance;
Then you just print out (or store) every time the service_id changes:
my $last_service_id = -8675309; # for a good time, call while ($sth->fetch()) { if ($service != $last_service_id) { print "min dist for service '$service' = '$distance' at stop ' +$stops'\n"; $last_service_id = $service; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with manipulating data from a database??
by dsheroh (Monsignor) on Jul 02, 2007 at 15:38 UTC | |
by ForgotPasswordAgain (Vicar) on Jul 03, 2007 at 08:36 UTC | |
|
Re^2: Help with manipulating data from a database??
by Harch84 (Acolyte) on Jul 02, 2007 at 15:17 UTC |