title: MySql Query : How to select data which is not exist in last 90 days from the given date value?
body: <p>I have one "User" table with fields UserId and addedDate.</p>
  
  <p>I need to get data of users - added in the last month and current month and not in system for 90 days prior to <strong>added</strong> <strong>date</strong>.</p>
  
  <p>User Table </p>
  
  <pre><code>Userid      addedDate         enddate
  001        2017-07-01       2017-09-05
  002        2017-02-25       2017-02-01
  003        2017-06-01       2017-09-21
  003        2017-04-25       2017-05-29
  004        2017-06-01       2017-09-21  
  005        2017-06-05       2017-09-07
  005        2017-01-01       2017-01-31
  </code></pre>
  
  <p>I need output like :</p>
  
  <pre><code>userid
    001
    004
    005
  </code></pre>
  
  <p>Here 003 is not required as its not a new user(as its available system for 90 days prior to <strong>added</strong> <strong>date</strong>). and 002 is not added in last moth or current moth, so this also cant consider as new user.</p>
  
  <p>I have tried below query but its not working fine :</p>
  
  <pre><code>select userid from usertbl final
  WHERE final.userid NOT IN (
  SELECT meb.userid 
  FROM usertbl meb 
  INNER JOIN 
  ( 
  SELECT mc.userid, addeddate, enddate 
  FROM usertbl mc 
  WHERE mc.enddate &gt; NOW() 
  AND mc.addeddate &gt; DATE_ADD(NOW(), INTERVAL -90 DAY) 
  ) s 
  ON s.userid = meb.userid 
  AND 
  (
  meb.enddate &gt; DATE_ADD(s.addeddate,INTERVAL -90 DAY) 
  AND meb.enddate &lt;&gt; s.enddate
  ) 
  )
  </code></pre>
  
  <p>Please provide some suggestions.</p>