title: Calculate difference between two dates and count the number of occurrences
body: <p>I am trying to calculate the difference between two dates and in the same query trying to count the frequency of occurence.</p>
  
  <pre><code>SELECT DATEDIFF(day,[Date1],[Date2]) AS 'Mydate'
       , count ([Mydate])    
    FROM Table1
   group 
      by 'Mydate'  
  </code></pre>
  
  <p>I am expecting the query to calculate and count but getting an error msg "Each GROUP BY expression must contain at least one column that is not an outer reference."
  what I am expecting is, something like this:</p>
  
  <pre><code>Mydate  Count
  0        5
  1        4
  2        5
  </code></pre>
  
  <p>Can someone help me please? Thanks</p>