2 つのテーブルを結合して合計を取得すると、正しい数値が得られます。
select
d.accn_id,
cast(d.load_date as DATE) as LoadDate,
cast (d.final_rpt_date as DATE) as FinalReportDate,
sum(p.paid_amt) as SumPaidAmt
from
accn_demographics d
join
accn_payments p
on
d.ACCN_ID=p.ACCN_ID
where
p.POSTED='y'
and p.PMT_DATE between '20120501' and '20120531'
group by
d.accn_id,
d.load_date,
d.final_rpt_date
ただし、別のテーブルaccn_payorsに参加した後:
select
d.accn_id,
cast(d.load_date as DATE) as LoadDate,
cast (d.final_rpt_date as DATE) as FinalReportDate,
sum(p.paid_amt) as SumPaidAmt
,payors.PAYOR_ID
from
accn_demographics d
join
accn_payments p
on
d.ACCN_ID=p.ACCN_ID
left join
accn_payors payors
on
payors.X_PAYOR_ID=p.X_PRICED_PAYOR_ID
and payors.ACCN_ID = p.ACCN_ID
where
p.POSTED='y'
and p.PMT_DATE between '20120501' and '20120531'
group by
d.accn_id,
d.load_date,
d.final_rpt_date
,payors.PAYOR_ID
私は誇張されていますsum(p.paid_amt)
問題は、複数回参加しないように参加を調整するにはどうすればよいですか?