(Note the use of placeholders ...)# Assumes the time is coming in as 12:47:02 sub get_pressure { my ($data_time) = @_; my $sql = <<__END_SQL__; SELECT weather_time ,baro_pressure FROM pressure WHERE weather_time < TO_DATE(?, 'HH:MI:SS') ORDER BY weather_time DESC __END_SQL__ my $sth = $dbh->prepare($sql) || die ... $sth->execute($data_time) || die ... $sth->bind_columns(\my ($press_time, $pressure)); # You only want the first column returned. $sth->fetch; return $pressure; }
You're looking for the largest weather_time, so you can just order them descending.
I'm not fully up on DBI::AnyData's restrictions. Personally, I would have used DBD::SQL_Lite and taken the overhead of the schema definition. *shrugs*
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: Re: Re: Data structure advice
by dragonchild
in thread Data structure advice
by robinbowes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |