I have a table call_log has about 10 million records in it.
I have query like:
select dnis, COUNT(1) as total, SUM(DATEDIFF(minute, time_in, time_out))
from call_log
where time_in bewteen @dt1 and @dt2
group by dnis
normally the date range will be about 1 month, and the total records during the selected period is about 15,000. Currently the query runs very slow (26 seconds after clear the cache).
I have index on the column time_in + dnis.
Is there any way to optimize it?
Thanks,