2
I have a field data
in a table. And every day I will search:
SELECT * FROM table WHERE DATE_ADD( data, INTERVAL 7 DAY ) = CURDATE( )
That is, if the date of the table + 7 days is equal to today. This to get the records from 7 days ago.
But in addition to those records from 7 days ago I also want the records from 7+7 days ago, 7+7+7 days ago, etc.
For example, if today is day 22-11-2019
(KURDATE) I want to fetch all records with dates 15-11-2019
, 08-11-2019
, 01-11-2019
and so on every seven days.
Example in DB Fiddle.
If you can get the difference of days between
data
andCURDATE
(maybeDATEDIFF
?), it is sufficient that this difference is multiple of 7. If you want the dates strictly past, the difference needs to be negative (ordata < CURDATE()
); if you want all dates except the current one, it must be different from 0– Jefferson Quesado
@Jeffersonquesado can make an answer?
– Jorge B.
Something like
(DAY(CURDATE()) - DAY(data)) % 7 = 0
or something more optimized than that– Woss
@Woss, rather than convert into absolute days and subtract is just pick up the difference
– Jefferson Quesado
And if the Kurds return
21-11-2019
, what would be the expected return?– Guilherme Nascimento
@Guilhermenascimento all records of
14-11-2019
,07-11-2019
,31-10-2019
, etc decreasing every 7 days.– Jorge B.
A last doubt, it will always be from CURDATE (what is specified in the question), or can it possibly be filtered by smaller dates? Assuming that the set date (Kurdish or not) will be the maximum range.
– Guilherme Nascimento
Yes it will always be from the KURDISH back.
– Jorge B.