This answer has shown me how to get annual changes from data:
UPDATE values_table as a
join values_table as b
ON b.date_sampled = DATE_SUB(a.date_sampled, INTERVAL 1 YEAR)
set a.annual_change = a.sample_value - b.sample_value
And this answer has shown me how to find the closest date to an INTERVAL
(relative to NOW()
with 3 results, in this question's case):
SELECT event_id FROM Table ORDER BY ABS( DATEDIFF( EVENT_START_DATE, NOW() ) ) LIMIT 3
How can the two be combined to get annual rates of change when the dates have holes, SELECT
ing the closest date to the desired INTERVAL
?
I finally had a chance to try Gordon's answer, but I'm getting Error in query (1054): Unknown column 'vt.date_sampled' in 'where clause'
.
I also tried to do a subquery based upon the second answer above after ON b.date_sampled =
, but it gives Error in query (1064): Syntax error near 'SELECT date_sampled FROM values_table ORDER BY ABS( DATE_SUB(a.date_sampled, INT'
.