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; } }
In reply to Re: Help with manipulating data from a database??
by ForgotPasswordAgain
in thread Help with manipulating data from a database??
by Harch84
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |