sql - SQL 查找以前的记录信息
问题描述
这是我的情况。我对一个人提出了一系列要求。我们偶尔会收到重复的索赔,该索赔给出了 DUP 错误代码,并以零美元金额被拒绝。我要做的是查找原始索赔单位和计费金额。如果副本和原始索赔是相同的单位和计费金额,我打算忽略它(或至少将其标记为不是潜在的重新计费)。如果单位和/或计费金额不同,则该索赔将被标记为潜在的重新计费。
我有一个函数可以正确找到原始声明主键值,并且基本查询在不到一秒的时间内运行。但是,当我尝试将该数据集链接回表时,它会将我的运行时间压缩到无用的地步。我不明白的是,为什么单独的函数运行得如此之快,但试图将其链接回来却使它陷入了如此多的困境,我们正在谈论一年活动中包含 140 次索赔的数据集。
如果有人可以提供一些见解或有更好的方法来实现这一点,我将不胜感激。
SELECT pre.*
--, st.unitsofservice as OrigUnits
--I only include the line above if the link to the servicetransaction table on the last line of the query is active
FROM
(
SELECT Sub.*--,
,dbo.cf_DuplicateServiceSTID(sub.servicetransactionid) as PaidSvc
--the line above is the function returning the primary key value for the original claim
FROM
(
SELECT Pre.servicetransactionID,
st.servicedate, st.individualid, st.agencyid, st.servicecode, st.placeofserviceid, st.unitsofservice,
dbo.sortmodifiers(st.modifiercodeid, st.modifiercodeid2, st.modifiercodeid3, st.modifiercodeid4) as Modifiers,
bd.billedamount,
a.upi,
b.name
FROM (select pmt.servicetransactionid
from pmtadjdetail pmt
where substring(pmt.reasoncodes,1,5) = 'DUP') Pre
JOIN servicetransaction st on pre.servicetransactionid = st.servicetransactionid
join billdetail bd on st.servicetransactionid = bd.servicetransactionid
join agency a on st.agencyid = a.agencyid
join business b on a.businessid = b.businessid
where st.servicedate between @StartDate and @EndDate
and st.agencyid = iif(@AgencyID is null, st.agencyid, @AgencyID)
) Sub
join individual i on sub.individualid = i.individualid
join enrollment e on sub.individualid = e.individualid
WHERE e.enrollmenttype <> 'p'
) Pre
--join servicetransaction st on pre.paidsvc = st.servicetransactionid
--If I remove the comment from the line above my run time increases to the point of uselessness
解决方案
推荐阅读
- c# - 实例化播放器时引用 scoreManager
- javascript - 我只想在javascript / node中用£替换£
- c# - 无法将井号向右移动
- java - Makefile:“多个目标模式。停止。”
- laravel - Laravel mix - 具有两个级别的路线上出现 404 错误
- vue.js - Vue2 从 api 回调中设置变量
- android - Moshi 序列化泛型类“找不到生成的 JsonAdapter 构造函数...”
- jenkins - Jenkins Groovy Sandbox In-ProcessApproval
- swift - 如何从子视图中隐藏 NavigationBar?
- javascript - 如何使用此构造函数中的另一个变量计算构造函数中的变量