title: Getting Count of Time Intervals
body: <p>I have a table called Call_Data and the data looks like:</p>
  
  <pre><code>Arr_Date      Interval    AN_Time    AB_Time
  08/08/2011    1600        113        NULL
  08/08/2011    1400        317        NULL
  08/09/2011    1200        298        NULL
  08/09/2011    1000        NULL       194
  08/10/2011    1200        256        NULL
  08/10/2011    1400        NULL       132
  </code></pre>
  
  <p>I am looking to get output like:</p>
  
  <pre><code>Arr_Date    Total_calls  AN_10_min   AN_5_min   AB_10_Min     AB_5_min
  08/08/2011   2             2            1             0           0
  08/09/2011   2             1            1             1           1
  08/10/2011   2             1            1             1           1
  </code></pre>
  
  <p>The logic is the column AN_Time,AB_Time is in seconds. I want to count the number of calls per day that are within 10min and 5 min range for each column.</p>
  
  <p>I wrote something like this:</p>
  
  <pre><code>SELECT  ARR_date,
  CASE WHEN AN_TIME &lt;300 THEN 1 ELSE 0 END AS AN_5_min ,
  case WHEN AN_TIME &lt;600 THEN 1 ELSE 0 END AS AN_10_min,
  CASE WHEN AB_TIME &lt;300 THEN 1 ELSE 0 END AS AB_5_min ,
  case WHEN AB_TIME &lt;600 THEN 1 ELSE 0 END AS AB_10_min
  FROM Call_Data
  GROUP BY AR_Date,AN_TIME,AB_TIME
  </code></pre>
  
  <p>But this doesn't gice me the total numbe of calls. Can anyone help me?</p>