I am using the following SELECT statement within a cursor in a procedure.
SET @chng = ( SELECT Tcle - cls
FROM dly
WHERE dt = SUBDATE(Tdt, INTERVAL 1 DAY);
AND dly.nms_id = Tnms_id);
Tdt
is the date of the current record.
The problem I have is that the records in my table do not have consecutive dates. So records in dly will have dates '11-01-2010'
then '12-01-2010'
and then '15-01-2010
' due to the weekend between.
That is where my SELECT
statement is flawed as if it is run on '15-01-2010
' as Tdt
, then:
WHERE dt = '14-01-2010'
but I want it to select the previous records date:
WHERE dt = '12-01-2010'
So is there a way to SELECT the previous records date?