所以我试图结合查询并做到这一点,我需要弄清楚这个是怎么回事。我对 sql server 还比较陌生,我不得不直接研究一些复杂的 qrys,有时我会陷入像这样的简单事情上。我的问题是使用了 Sum(1) 函数,我不完全确定如何使用。这意味着我相信它正在计算重复项,但我无法根据它正在执行的信息来判断。
这是查询
SELECT
qryReinsuranceDPA1.POLICY_NO,
qryReinsuranceDPA1.PHASE_CODE,
qryReinsuranceDPA1.SUB_PHASE_CODE,
qryReinsuranceDPA1.ProdType,
TotalDPA = Sum(case when [SumOfNetDefExtraAdj] Is Null then [SumOfNetDefPremiumAdj] else [SumOfNetDefPremiumAdj] + SumOfNetDefExtraAdj end),
Sum(1) AS Expr1
FROM qryPolicyListforNYDefPRemAsset_Re RIGHT JOIN qryReinsuranceDPA1
ON
qryReinsuranceDPA1.POLICY_NO = qryPolicyListforNYDefPRemAsset_Re.POLICY_NO AND
qryReinsuranceDPA1.PHASE_CODE= qryPolicyListforNYDefPRemAsset_Re.PHASE_CODE AND
qryReinsuranceDPA1.SUB_PHASE_CODE = qryPolicyListforNYDefPRemAsset_Re.SUB_PHASE_CODE
GROUP BY qryReinsuranceDPA1.POLICY_NO,
qryReinsuranceDPA1.PHASE_CODE,
qryReinsuranceDPA1.SUB_PHASE_CODE,
qryReinsuranceDPA1.ProdType
--HAVING (((Sum(1))<>1))
GO
这是它产生的一个小样本(实际结果数约为 77,000)
POLICY_NO PHASE_CODE SUB_PHASE_CODE ProdType TotalDPA Expr1
228433800 0 1 TERM 282.324223 1
228439200 0 1 PERM 53.17048634 1
228439200 6 1 PERM 10.3805065 1
228441500 0 1 PERM 526.6883742 1
228441500 0 2 PERM 10.63320899 1
228441700 0 1 PERM 20.86247317 1
228448100 0 1 PERM 345.2117169 1
228460200 0 1 TERM 302.7574933 1
228464900 0 1 TERM 191.2597906 1
228468000 0 1 PERM 8445.190912 1
228473600 0 1 TERM 339.8413682 **2**
228473800 0 1 TERM 686.1766864 **2**
228477200 0 1 TERM 583.7580207 1
228481200 0 1 TERM 362.9472595 1
228481200 0 2 PERM 4.217792443 1
228482500 0 1 PERM 1894.303507 1
228482500 1 1 TERM 1312.183889 1
228491600 0 1 TERM 325.0796843 **2**
228494400 0 1 PERM 748.2710255 1
228501000 0 1 TERM 47.78070676 1
228501100 0 1 TERM 47.78070676 1
228501300 0 1 PERM 365.5651862 1
228501300 0 2 PERM 12.20547324 1
228501300 1 1 TERM 706.0961491 1
228501300 1 2 PERM 12.46769547 1
228502000 0 1 PERM 6562.164879 1
228502000 0 2 PERM 184.7741277 1
最右边的列是 Sum(1) 的结果,我想知道它何时以及为什么会产生 2。