title: How to get the output column using a sql query basis the logic
body: <pre><code>Date              id    output     
  11/26/2018 12:24   A    1    
  12/10/2018 23:34   A    0    
  12/11/2018 16:03   A    0   
  12/11/2018 16:34   A    0    
  12/12/2018 9:58    A    0    
  12/13/2018 9:27    A    1    
  12/6/2018 8:48     B    1    
  12/26/2018 8:49    B    1
  </code></pre>
  
  <p>I'm trying to create a new column which has a value of 1 or 0 basis the logic.</p>
  
  <ol>
  <li>For each unique value of id if the difference of the max value of date and min value of the date is > 15 days - output is 1 else 0</li>
  <li>else if the date difference is &lt; 15 days and id has a count(id) > 1 - output is 0 else 1</li>
  <li>last row for each unique id - output should be always 1</li>
  </ol>
  
  <p>I'm trying to implement the logic in a SQL query to get the output column to be 1 or 0 basis the logic. Can anybody help me.</p>