sql - SQL 查询优化和 SSRS 报告性能
问题描述
下面的代码来自 SSRS 报告,该报告需要很长时间才能执行。它从包含数百万条记录的存档表中检索数据。代码不是我写的,所以不太了解。有没有办法优化以下代码?这是从活动监视器检查时导致问题的代码的一部分。在数据库中创建索引也需要很长时间。有没有更好的方法?
Insert into #MandrillResponses
select EmailResultID, eventtype,
case when IsNull(count(*),0) > 0 then 1 else 0 end
from #EmailsSent s
join TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype not in ('open','click','Deferral')
group by EmailResultID, eventtype
insert into #MandrillResponses
select EmailResultID, eventtype, max(count)
from #EmailsSent s
join TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype in ('open','click','Deferral')
group by EmailResultID, eventtype
UNION
select EmailResultID, eventtype, max(count)
from #EmailsSent s
join archive_TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype in ('open','click','Deferral')
group by EmailResultID, eventtype;
解决方案
推荐阅读
- html - 无法使用 angular4 中的 PipeTransform 进行反向排序
- powershell - Powershell 出错时恢复
- java - 为什么 Spring-data-jdbc 不保存我的 Car 对象?
- node.js - 批量创建后 Sequelize 不会关闭
- c++ - CLR dll 无法运行托管 DLL,除非它位于 exe 目录(或其子目录)中
- c - 为什么我从递归函数返回的值是错误的
- r - 从另一个矩阵创建矩阵
- java - java.util.Locale 返回它构建时使用的不同语言
- excel - 通过 Win32com 从 Python 到 Excel 的 Bloomberg 公式
- push-notification - 我可以向那些卸载了我的安卓应用程序的用户发送推送通知吗?