August 16, 2012 at 4:50 am
As the title says
select
id
, count(distinct company) as CompanyCount
, count(distinct district) as DistrictCount
from Tracking
group by id
thanks in advance
August 16, 2012 at 4:55 am
August 16, 2012 at 5:16 am
Index intersection might work with the 2 indexes, but it might not. If not, you could try the same two indexes and then use a UNION ALL query to put the information back together.
I'd also experiment with a single index, either id, company, whatever it was, or id, whatever, company.
Check the execution plans to see which use the indexes best.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
August 16, 2012 at 8:51 am
It would be also nice to see actual plan in xml. And maybe some info about a table, e.g. size, structure and indexes.
August 16, 2012 at 9:19 am
erics44 (8/16/2012)
As the title saysselect
id
, count(distinct company) as CompanyCount
, count(distinct district) as DistrictCount
from Tracking
group by id
thanks in advance
Depending on how wide the table is, a nonclustered index on id with included columns company and district may speed up the query. Of course, knowing more about the data would help as well.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply