My DB is SQL SERVER 2008
I have a large table with 100 million rows and 50 columns.
All the datatype is int.
Then , My query is like ….
Select Count(distinct col5) , Count(distinct col8) , Sum(Col 30) , Sum(Col 49)
Group by Col1
Select Count(distinct col5) , Count(distinct col8) , Sum(Col 30) , Sum(Col 49)
Group by Col1,col2
.....
Select Count(distinct col5) , Count(distinct col8) , Sum(Col 30) , Sum(Col 49)
Group by Col1 ,Col2,Col3,Col4,Col6,Col7
(about 180 queries ...like above)
But the performance is very bad when I use the count distinct.
So , who can teach me how to improve it please?
and in my case how long might be cost with a best solution ?
very thanks your advices ….
These queries (without
WHEREclauses) can hardly be optimized since they need to visit every record to calculate the sums no matter what.Full table scan and a temporary table to hold the results is a best solution and that’s what you most probably have in your plan.