sql - SQL 性能问题
问题描述
如果有任何其他方法可以编写下面的查询来派生日期参数,你们能帮忙吗?我正在尝试添加一个功能,如果需要,可以根据标志从表中派生日期参数。
这是我之前立即运行的内容:
select distinct
baf.AccountEpicId "encounterepiccsn" --aliased because this is what everything references
from
billingaccountfact baf
Where
(1=1
and baf.accountdatekey > 0
and baf.accountdatekey not in (-1,-2,-3)
and cast(convert(char(8), baf.accountdatekey,112) as date) >= DateAdd(Day, DateDiff(Day, 0, GetDate()-1), 0)--Account Key greater than the StartDate
and cast(convert(char(8), baf.accountdatekey,112) as date) <= DateAdd(Day, DateDiff(Day, 0, GetDate()), 0)
)
这是我所做的更改,但性能需要超过 4 分钟:
select distinct
baf.AccountEpicId "encounterepiccsn"
from
billingaccountfact baf
LEFT JOIN ADS_Config D ON D.ObjectName='ADSEncountersVW'
AND D.DateOverride =1
Where
(1=1
and baf.accountdatekey > 0
and baf.accountdatekey not in (-1,-2,-3)
and cast(convert(char(8), baf.accountdatekey,112) as date) >= ISNULL(D.StartDate ,DateAdd(Day, DateDiff(Day, 0, GetDate()-1), 0))--Account Key greater than the StartDate
and cast(convert(char(8), baf.accountdatekey,112) as date) <= ISNULL(D.EndDate ,DateAdd(Day, DateDiff(Day, 0, GetDate()), 0))
)
解决方案
推荐阅读
- sql - 如何在 SQL Server 中为我的数据库和表生成脚本
- python-3.x - 将 Sheets API 'batchGet' 请求转换为 Pandas DataFrame
- tensorflow - 为什么这个 GradientDescentOptimizer 会卡住?
- swift - 我应该如何从 firebase 检索数据并将其放入字典中?
- github - 在 conda 中使用 pip 从 CGE 错误中安装 SCCmecfinder
- shell - 如何在创建新的分离会话时告诉 tmux 以随后发出另一个 tmux 命令
- sql-server - 如何解决这个存储过程问题?
- algorithm - 如何直观地解释 S 型神经网络模型?
- sql - 在 Oracle SQL 表中查找带双引号的字段
- php - 如果不存在,则将多个值插入表 MySQL