#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    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
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,166
    Rep Power
    4274
    Code:
    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
    this might appear to be redundant, but the first line is to enable indexed retrieval
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo