Calculate difference between two dates and count the number of occurrences

Viewed 3607

I am trying to calculate the difference between two dates and in the same query trying to count the frequency of occurence.

SELECT DATEDIFF(day,[Date1],[Date2]) AS 'Mydate'
     , count ([Mydate])    
  FROM Table1
 group 
    by 'Mydate'  

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:

Mydate  Count
0        5
1        4
2        5

Can someone help me please? Thanks

2 Answers
Related