0

我有一个为客户维护的 Access 数据库。

我有 4 张桌子。索赔、资格、药房和代码。

我使用的主键是 PHID + SID = MemberID,我链接到每个表,然后代码表仅用于描述。请参阅下面的查询以获得更好的可视化...

查询 1:Member_Claims_Query

SELECT
Eligibility.GROUPID, 
Eligibility.PHID & '-' & Eligibility.SID AS MemberID, 
[Eligibility].[DOB] AS DOB, 
Eligibility.GENDER, 
Eligibility.RELATIONSHIP_CODE, 
MaxDiagDollars.HighestDiagPaid/SUM(Claims.PAID_AMT) AS ['%'],
MaxDiagDollars.HighestDiagPaid/SUM(Claims.PAID_AMT) as 'Percent',
ROUND(SUM(Claims.PAID_AMT)) AS TOTALPAID,
ROUND(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2011',Claims.PAID_AMT,0))) AS 2011TOTALPAID, 
ROUND(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2012',Claims.PAID_AMT,0))) AS 2012TOTALPAID, 
ROUND(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2013',Claims.PAID_AMT,0))) AS 2013TOTALPAID
FROM (Claims 
INNER JOIN Eligibility 
ON (Claims.[SID] = Eligibility.[SID]) AND (Claims.[PHID] = Eligibility.[PHID])) 
INNER JOIN (SELECT PHID, SID, MAX(TotalPaid) AS HighestDiagPaid 
FROM (SELECT [PHID], [SID], DIAG_CODE1, SUM(PAID_AMT) AS TotalPaid FROM Claims GROUP BY [PHID], [SID], [DIAG_CODE1])  AS [%$##@_Alias] GROUP BY PHID, SID)  AS MaxDiagDollars ON ( MaxDiagDollars.[PHID]=Eligibility.[PHID] ) AND ( MaxDiagDollars.[SID] = Eligibility.[SID] )
WHERE Eligibility.DOB < DateAdd( 'y', -2, DATE())
GROUP BY 
Eligibility.GROUPID, Eligibility.PHID & '-' & Eligibility.SID, [Eligibility].[DOB], Eligibility.GENDER, Eligibility.RELATIONSHIP_CODE, MaxDiagDollars.HighestDiagPaid
HAVING SUM(Claims.PAID_AMT)>10000 and  MaxDiagDollars.HighestDiagPaid/SUM(Claims.PAID_AMT) <= 0.80;

此查询应该获取每个成员支付的总金额并给出总金额 PAid,然后每年爆发。

查询 2:Member_By_Diag

SELECT 
Eligibility.PHID & '-' & Eligibility.SID AS MemberID, 
Claims.Diag_Code1, 
ROUND(Sum(Claims.PAID_AMT)) AS TotalPaid, 
ROUND(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2011',Claims.PAID_AMT,0))) AS 2011TotalPaid, 
ROUND(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2012',Claims.PAID_AMT,0))) AS 2012TotalPaid, 
ROUND( Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2013',Claims.PAID_AMT,0))) AS 2013TotalPaid
FROM 
(Claims 
INNER JOIN Eligibility 
ON (Claims.[SID] = Eligibility.[SID]) AND (Claims.[PHID] = Eligibility.[PHID])) 
INNER JOIN Pharmacy 
ON (Eligibility.SID = Pharmacy.SID) AND (Eligibility.PHID = Pharmacy.PHID)
GROUP BY 
Eligibility.PHID & '-' & Eligibility.SID,  Claims.Diag_Code1
HAVING count( [Pharmacy].[NDC] ) >4 and count(IIF(Claims.REV_CODE= '450',1,0) ) > 1
ORDER BY Eligibility.PHID & '-' & Eligibility.SID;

第二个查询本质上应该获取每个成员的代码,并通过诊断代码分解他们支付的金额。

查询 3:combined_query

SELECT *
FROM (Member_Claims_Query AS a INNER JOIN Member_by_Diag AS b ON a.MemberID=b.MemberID) INNER JOIN Codes AS c ON c.DxCode = b.Diag_Code1;

ISSUE 我的客户给我发了一封电子邮件,说明 Member_By_Diag 查询中的总支付额有时高于 Member_By_Claim 查询中的总支付额。但是它们的计算方式相同。

我打开数据库并编写了一个简单的查询,以查看在 b.Total_Paid (Member_By_Diag.Total_Paid) 大于 Member_Claims_Query.Total_Paid 时返回了多少记录。

在这种情况下,它返回了 262/1278 条记录。

SELECT * FROM Combined_Query WHERE b_TotalPaid > a_TotalPaid

这张照片准确地描述了我和我的客户所看到的。结论性结果1

如你看到的。a_TotalPaid > b_TotalPaid。但是,如果您查看我的查询,它们是否相同?这是按问题分组吗?还是加入问题?任何帮助将非常感激。

4

2 回答 2

0

可能导致此问题的查询之间存在一些差异。罪魁祸首是您的 INNER JOIN 语句和 HAVING 语句。这些很容易排除会影响您的 TotalPaid 字段的记录。如果没有原始数据集,我无法告诉您太多,但您可能希望运行这些查询并尝试删除和插入各种 INNER JOIN 和 HAVING 子句,以查看哪个正在删除导致您的总数不存在的记录平等的。

于 2013-08-08T11:54:53.863 回答
0

我很感谢大家的答案......你没有完全回答这个问题,但是 Pharmacy 的内部连接导致了这个问题,我专门将它用于 HAVING 子句,当我添加一个计数(*)时,我注意到它实际上使我的结果成倍增加。对于前。如果一个会员有 7 条索赔和 6 条药房记录,它会成倍增加,使其成为 42 条记录,使我的总支付非常高,而且它们与索赔本身无关……因此是最终问题。这是 Member_By_Diag 查询中的解决方案:

    SELECT Eligibility.PHID & '-' & Eligibility.SID AS MemberID, Claims.Diag_Code1, Round(Sum(Claims.PAID_AMT)) AS TotalPaid, Round(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2011',Claims.PAID_AMT,0))) AS 2011TotalPaid, Round(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2012',Claims.PAID_AMT,0))) AS 2012TotalPaid, Round(Sum(IIf(Format(Serv_Beg_Date,'yyyy')='2013',Claims.PAID_AMT,0))) AS 2013TotalPaid, Count(*) AS Expr1
FROM (Claims INNER JOIN Eligibility ON (Claims.[SID] = Eligibility.[SID]) AND (Claims.[PHID] = Eligibility.[PHID])) INNER JOIN ***(SELECT PHID, SID, COUNT(NDC) AS RXCount FROM Pharmacy GROUP BY PHID, SID ORDER BY PHID, SID)  AS Pharmacy*** ON (Eligibility.SID = Pharmacy.SID) AND (Eligibility.PHID = Pharmacy.PHID)
GROUP BY Eligibility.PHID & '-' & Eligibility.SID, Claims.Diag_Code1
***HAVING Count(IIf([Claims].[REV_CODE]='450',1,0))>1***
ORDER BY Eligibility.PHID & '-' & Eligibility.SID;

这使得美元看起来更加合理。感谢大家。

于 2013-08-08T13:12:43.390 回答