For the cost of a single table scan, you may be better with:

select max(foo) - min(foo) where etc.

S.

--
Anyone using floating point for financial computations needs their head examined.

On 12/20/18 4:32 PM, Jens Alfke wrote:


On Dec 20, 2018, at 4:21 PM, Jungle Boogie <jungleboog...@gmail.com> wrote:

select od_reading from mileage where car='foo' limit 1
select od_reading from mileage where car='bar' order by od_reading desc limit 1

Note: the first query should use “order by od_reading”, otherwise the order is 
undefined.

A clearer way to specify these is
        select min(od_reading) from mileage where car=‘foo’
        select max(od_reading) from mileage where car=‘foo’

How do I subtract the last query from the first query to determine how many
miles were driven?

It’s super simple:

(select od_reading from mileage where car='foo' limit 1) - (select od_reading 
from mileage where car='bar' order by od_reading desc limit 1)

—Jens
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to