sql server 2005 - What is the fastest way to group a DateTime column by Date in T-SQL -


I have an old SQL 2005 box, and I need to summarize a table with 500M lines.

I have a time table column in the table and I want to get it for output and group only by date. I know there are some ways to do this, but what is the fastest speed?

Thanks

I doubt will be the fastest:

  SELECT the_day = DATEADD (day, the_day, '19000101'), the_count FROM (SELECT the_day = DATEDIFF (DAY, '19010101', [the_datetime_column]), the_count = COUNT (* ) From dbo.the_table group by DATEDIFF (DAY, '19000101', [the_datetime_column]) WHERE ...) AS;   

But the "fastest" is relative here, and it will depend on the index on the table, how are you filtering rows, etc. You can call it other normal date-end methods, such as CONVERT (CHAR (8), [the_datetime_column], 112) .

What can you think - according to this question, whether this query is more important to write more - an index, or indexed view, is adding a continuously calculated column, which The question will help this aggregation for you at the time of writing instead of time.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -