title: SQL query for finding finished records published for different time periods
body: <p>So imagine there is a blog and the owner can publishe his posts for different time periods, for example: </p>
  
  <ul>
  <li>1 week</li>
  <li>2 weeks </li>
  <li>1 months </li>
  <li>2 months</li>
  <li>6 months</li>
  </ul>
  
  <p>after which the post should be deleted.</p>
  
  <p>The time period is set in the column named, well , <code>time_period</code>, with integer value in it with <code>0</code> standing for 1 week, <code>1</code> standing for 2 weeks and etc</p>
  
  <p>The date of creation is set in <code>created_at</code> column.</p>
  
  <p>And so I need to write a sql query to fetch all the records that have expired publication date and there are 2 ways I can see to solve this problem: </p>
  
  <p>1) Write a query with a lot of conditions like:</p>
  
  <pre><code>.where("(time_period = 0 AND created_at &lt;= :one_week_ago) OR
          (time_period = 1 AND created_at &lt;= :two_weeks_ago)",
           one_week_ago: Time.now - 1.week, 
           two_weeks_ago: Time.now - 2.weeks)
  </code></pre>
  
  <p>but for all the conditions</p>
  
  <p>2) Or simply fetch all the records (with <code>find_each</code> method) and check each one for meeting the requirements</p>
  
  <p>and I will probably go with the second one but I just wonder if there's an efficient way to write a query for this kind of situation ? Maybe some database functions or something like that?</p>