简体   繁体   中英

Slow query using sum in SQL Server

I have a table in SQL Server 2014 with over 15 million rows and 49 columns. A simple query like this takes about 20 seconds to run. Is there any other ways to fine tune it? Date_run and skid are both indexed non clustered.

select skid, sum(price)
from stocktrack
where date_run >='2013-2-21'
  and date_run <='2013-3-21'
group by skid

Maybe you could reduce the amount of data to scan by partition the table on [date_run] column. It depends on the data variation in the column. You should get the execution plan before and after to check the behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM