Board index » delphi » Grouping by year
Joe Bain
![]() Delphi Developer |
Grouping by year2006-03-14 05:23:18 AM delphi62 I need to do some reporting by year. I need the some of the money values from 3 detail tables grouped by the year that the transaction took place. The relationship between claimmaster and the other tables are all 1 to many. My problem is that the joins are causing all the values to get multiplied when there are multiple detail records. Is there away to make this work without using temp tables (ie select from (select from)), I don't think they are in interbase, or at least the version the customer has. Sorry about the formatting. select c.CLAIMNUMBER, r.RESERVETYPE, extract(YEAR from r.CREATEDATE) , sum(coalesce(r.RESERVECHANGEAMT,0)), sum(coalesce(p.DETAILPAYMENTAMT,0)), sum(coalesce(s.RECOVERYAMOUNT,0)) from CLAIMMASTER c left join RESERVEHISTORY r on (c.CLAIMMASTERRECORDID = r.CLAIMMASTERRECORDID) left join PAYMENTDETAIL p on (c.CLAIMMASTERRECORDID = p.CLAIMMASTERRECORDID and r.RESERVETYPE = p.RESERVETYPE and (extract(YEAR from r.CREATEDATE) = extract(YEAR from p.CREATEDATE))) left join SALVSUBRORECOVERY s on(c.CLAIMMASTERRECORDID = s.CLAIMMASTERRECORDID and r.RESERVETYPE = s.RESERVETYPE and (extract(YEAR from r.CREATEDATE) = extract(YEAR from s.CREATEDATE))) group by 1, 2, 3 order by extract(YEAR from r.CREATEDATE), c.CLAIMNUMBER, r.RESERVETYPE ---------------- Joe Bain www.iegsoftware.com |