September 25th, 2012, 09:44 AM
My SQL Help
Help me in constructing a MySql Query to retrieve the rows based on datetime column.
Below are the conditions:
1)The date difference between today and date in that column sholud be =>2 days.
2)If the day of the date in DB column is Thursday/ Friday then the date difference between today and date in that column sholud be =>4 days.
Basically , I want all the rows that 2 days older considering 'Saturday & Sunday' as holidays.
Thx in Advance
September 25th, 2012, 10:53 AM
this might appear to be redundant, but the first line is to enable indexed retrieval
WHERE dt <= CURRENT_DATE - INTERVAL 2 DAY
AND dt <= CURRENT_DATE - INTERVAL
CASE WHEN DAYOFWEEK(dt) IN ( 1,7 )
THEN 4 ELSE 2 END DAY