Dear readers
I am looking for a way to optimize some queries
My (example) table is
ID I Date1 I Val1
010 I 01-03 I 1
019 I 02-03 I 0
167 I 03-03 I 4
472 I 04-03 I 5
etc, so multiple more records...
I creates a compare SQL between the two records with a nested SQL
SELECT DATE1, VAL1, (SELECT TOP 1 VAL1 from mytable where ID < tbl1.ID ORDER BY ID DESC) as PREV from Mytable as tbl1
Result is exactly what I want
Date1 I Val1 I PREV
01-03 I 1 I
02-03 I 0 I 1
03-03 I 4 I 0
04-03 I 5 I 4
This takes however a long time (even with a good WHERE clausule) to create with many records. Does somebody can advice me to do this more efficient?
Many thanks
Ben
I am looking for a way to optimize some queries
My (example) table is
ID I Date1 I Val1
010 I 01-03 I 1
019 I 02-03 I 0
167 I 03-03 I 4
472 I 04-03 I 5
etc, so multiple more records...
I creates a compare SQL between the two records with a nested SQL
SELECT DATE1, VAL1, (SELECT TOP 1 VAL1 from mytable where ID < tbl1.ID ORDER BY ID DESC) as PREV from Mytable as tbl1
Result is exactly what I want
Date1 I Val1 I PREV
01-03 I 1 I
02-03 I 0 I 1
03-03 I 4 I 0
04-03 I 5 I 4
This takes however a long time (even with a good WHERE clausule) to create with many records. Does somebody can advice me to do this more efficient?
Many thanks
Ben