sql server - Optimise SQL query with Case and operations in the select statement -


is there way optimise query below.

it takes around 2 minutes run

i'm using ms sql. records_table has 9 million records. date field stored in 30 minute intervals , there 60 different types of groups

declare @date datetime set @date = convert(datetime,'16/sep/2013',104)  select  [group], case when (sum(a) + sum(b)) = 0 0 else  cast(sum(c) decimal(18, 2)) / (sum(a) + sum(b)) * 100 end calculation    records_table date between @date , @date + 6 group [group] 

note need full week of data, i've set condition date between @date , @date + 6

any appreciated.

thanks

try partitioning table based on date, because understand conditions based on date, , can create index on date, because of 9 million row have prefer partitioning.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -