Hi All,

This is more of a how do I do this in sql question. I apologize in advance
for a simple question, but I need to learn somehow, so any pointers are 
appreciated.

My very simple schema:

CREATE TABLE mileage (
date text,
"car" text,
"od_reading" integer
)

Some sample data:
2018/04/15,foo,170644
2018/04/15,bar.69625
2018/04/22,foo,170821
2018/04/22,bar,69914
2018/04/29,foo,171006
2018/04/29,bar,70123
2018/05/06,foo,171129
2018/05/06,bar,70223
2018/05/09,foo,171178
2018/05/20,foo,171304
2018/05/20,bar,70517

I can select the first and last od_readings pertaining to a particular car this
way:
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

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

Next, is there an elegant way to see how many miles difference there is between
two readings of the same car?

For instance, how many miles difference are there between bar on 2018/05/20 and
2018/05/06?

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

Reply via email to