Hi
These NULLs cause this result
name OD start finish diff
Kelon Decee 637381 637381 NULL NULL
Kelon Decee 637500 637500 637381 119
Kelon Decee 637782 637782 637500 282
Noren Boley 635729 635729 NULL NULL
Noren Boley 635917 635917 635729 188
Noren Boley 636129 636129 635917 212
please modify CALCULATED FIELD cfLegMileage
IFNULL((select max(x.od) from bleg x where x.od = bleg.od and x.id_atrip = atrip.id)
-
(select max(x.od) from bleg x where x.od < bleg.od and x.id_atrip = atrip.id),0)
and simplify , works faster
IFNULL((SELECT bLeg.OD - max(b.OD) FROM bLeg b WHERE bLeg.id_aTrip = b.id_aTrip and b.OD < bLeg.OD),0)
AFTER
name OD start finish diff res
Kelon Decee 637381 637381 NULL 0
Kelon Decee 637500 637500 637381 119
Kelon Decee 637782 637782 637500 282
Noren Boley 635729 635729 NULL 0
Noren Boley 635917 635917 635729 188
Noren Boley 636129 636129 635917 212
You need to be careful when you create your databases and queries to it.
If you create related columns in your tables, then do not forget to fill them in these tables.
If you refer to a table in a query and mention a related column in another table,
do not forget about the JOIN (INNER or LEFT) of the other table ON related column.
If you have created a column, think about whether to put a default value (zero or something else).
I drew your attention to these things in the previous topic.
Yes, your project has gone relatively far, but you need to strive to simplify and optimize databases, tables, queries.
To test the correctness of your program, create yourself a database with the most correct data.
Otherwise, you will end up running in circles between your code and the database.
Strive for your program to fill in all the necessary data in the tables and then work with the output forms.
Create a form for yourself with one table and display the data of the tables in it one by one to control the correctness of filling.
To work with the database, you can use SQLlite administration programs.
Everything else works correctly in an MVD program (almost ).
Sorry. Translate by Google.