On Thursday, 20 December, 2018 17:32, Jens Alfke <j...@mooseyard.com> 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)

Or, more simply,

select max(od_reading) - min(od_reading) as miles_driven from mileage where 
car='bar';

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.




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

Reply via email to