The query is executing very slowly, is there any way to improve it any further?

后端 未结 8 1154
长情又很酷
长情又很酷 2021-02-15 17:26

I have the following query, and because of a lot of SUM function calls, my query is running too slow. I have a lot of records in my database and I would like to get

8条回答
  •  我寻月下人不归
    2021-02-15 17:51

    Just use computed colums

    Example

    ALTER TABLE tb1 ADD [Current - Last 30 Days Col1] AS (CASE WHEN a.DateCol >= DATEADD(MONTH,-1,GETDATE()) THEN a.col1 ELSE 0 END) PERSISTED;
    

    Specify Computed Columns in a Table

提交回复
热议问题