P
pat12
Hello everyone
Table1 contain car journal with nb of km on Counter after each journey
To calculate the distance of one trip I would like to have the Counter
status from the previous one.
Here is what I did:
SELECT a.Order, a.Date, a.Place, a.CarNb, a.Counter, b.Counter
FROM Table1 AS a LEFT JOIN Table1 AS b ON (b.Data<a.Data) AND
(a.CarNb=b.CarNb) AND (a.Order<>b.Order) 'could be more than one record
for one trip but counter is filled in the last one'
WHERE (b.Date = (SELECT Max(c.Date) FROM Table1 AS c WHERE a.Order <>
c.Order AND a.CarNb=c.CarNb AND c.Date<a.Date ) or b.Date is Null);
and its works fine with few hundreds records. But when nb of records
is more than 5000 Its 10 minutes to have results. The problem is that
the Table1 is to have about 200 000 records and than this is useless.
What should I do to increase query speed (except indexing of course).
Rebuild it? How? Maybe some better (different) solution?
Any help appreciated
PAT
Table1 contain car journal with nb of km on Counter after each journey
To calculate the distance of one trip I would like to have the Counter
status from the previous one.
Here is what I did:
SELECT a.Order, a.Date, a.Place, a.CarNb, a.Counter, b.Counter
FROM Table1 AS a LEFT JOIN Table1 AS b ON (b.Data<a.Data) AND
(a.CarNb=b.CarNb) AND (a.Order<>b.Order) 'could be more than one record
for one trip but counter is filled in the last one'
WHERE (b.Date = (SELECT Max(c.Date) FROM Table1 AS c WHERE a.Order <>
c.Order AND a.CarNb=c.CarNb AND c.Date<a.Date ) or b.Date is Null);
and its works fine with few hundreds records. But when nb of records
is more than 5000 Its 10 minutes to have results. The problem is that
the Table1 is to have about 200 000 records and than this is useless.
What should I do to increase query speed (except indexing of course).
Rebuild it? How? Maybe some better (different) solution?
Any help appreciated
PAT