I have a query below that I use to retrieve the records not updated for a given time (in hours) and order it by elapsed time:
SELECT TABLE.Key, TIMESTAMPDIFF(HOUR, TABLE.Date_last_consulted, CURRENT_TIMESTAMP)
FROM TABLE WHERE TIMESTAMPDIFF(HOUR, TABLE.Date_last_consulted,
CURRENT_TIMESTAMP) <= 7 ORDER BY TIMESTAMPDIFF(HOUR, TABLE.Date_last_consulted,
CURRENT_TIMESTAMP);
As you can see, it calls multiple times TIMESTAMPDIFF, which is not very efficient as all these calls lead to useless SQL calculations.
I was wondering if there were a way to reuse the calculations so it is processed only once?
Thanks a lot for your help.
Florent
1 Answer