I have a table of registrations, around 300K records. I need a SQL statement that will show the total number of registrations for that particular day?
select
count('x'),CONVERT(varchar(12),date_created,111)
from reg group by
cONVERT(varchar(12),date_created,111)
order by
CONVERT(varchar(12),date_created,111)
Result of this query:
169 2011/03/24
3016 2011/03/25
2999 2011/03/26
Desired outcome:
2011/03/25 3016+169
2011/03/26 2999+3016+169
How can this be done?
Here is two versions to do this. I have tested with 100000 rows spread over 6000 days on a really slow computer with not enough memory, and that shows that the cte version is faster than the loop version. The other versions suggested here (so far) is a lot slower, provided that I have understood the problem correctly.
Recursive CTE (10 seconds)
Loop (14 seconds)
Edit 1 The really fast version
The quirky update