I’m not sure this is even possible but I know if it is, the stackoverflow community is where I’ll find the answer. I’m basically trying to pre-process some data so that I can speed up my application. Here is an example of what I’m trying to do:
SELECT id
FROM data AS data1
WHERE rangeVal < (SELECT rangeVal FROM data WHERE id = data1.id - 1)
AND actiondate >= '1980-05-18'
AND actiondate <= '2012-05-18'
ORDER BY actiondate DESC
Essentially, I’m trying to get the IDs of my data only if their rangeVal is less than the rangeVal from the next day.
Any help or points in the right direction would be greatly appreciated!!
If your days are incremental and you have a row for each day, rather than try to rely on subtracting from an incremental id, which can be highly unreliable due to row deletions and other issues, you can join against the table using the
DATE_SUB()orDATE_ADD()as the join condition: