查询执行非常缓慢,是否有任何方法可以进一步改善它?
我有以下查询,由于有很多SUM函数调用,我的查询运行太慢。我的数据库中有很多记录,我希望获得当年和去年(过去30天,过去90天和过去365天)的报告: SELECT b.id as [ID] ,d.[Title] as [Title] ,e.Class as [Class] ,Sum(CASE WHEN a.DateCol >= DATEADD(MONTH,-1,GETDATE()) THEN a.col1 ELSE 0 END) as [Current - Last 30 Days Col1] ,Sum(CASE WHEN a.DateCol >= DATEADD(MONTH,-1,GETDATE()) THEN a.col2 ELSE 0 END) as [Current - Last 30 Days Col2] ,Sum(CASE WHEN a.DateCol >= DATEADD(QUARTER,-1,GETDATE()) …