我的查询:
select
SUM(payments.paid_amt) as paid_amt,
SUM(payments.copay_amt) as copay_amt,
SUM(payments.CO_INSURANCE_AMT) as co_ins_amt,
payor_group.PAYOR_GROUP as payor_group,
DATEPART(MM,accession.XIFIN_LOAD_DATE) as load_month,
DATEPART(yyyy,accession.XIFIN_LOAD_DATE) as load_year,
accession.ACCESSION_ID
from
[F_PAYOR_PAYMENTS_monthly] payments
join D_PAYOR payor
on payor.PAYOR_ID=payments.PAYMENT_PAYOR_ID
join D_PAYOR_GROUP payor_group
on payor.PAYOR_GROUP_KEY=payor_group.PAYOR_GROUP_KEY
join F_ACCESSION_daily accession
on accession.ACCESSION_ID=payments.ACCESSION_ID
where accession.XIFIN_LOAD_DATE between '20120501' and '20120531'
group by payor_group.PAYOR_GROUP, DATEPART(MM,accession.XIFIN_LOAD_DATE),
DATEPART(yyyy,accession.XIFIN_LOAD_DATE),accession.ACCESSION_ID
出于某种原因,它们多次SUMs
计数相同。accession.ACCESSION_ID
当我进行所有这些连接时,我担心我可能SUMming
多次使用相同的值。
我怎样才能确保我accession.ACCESSION_ID
只计算一次?
非常感谢您的帮助和指导。