SELECT
nm.Name as Payor,
SUM(di.DistributionAmount) AS TotalDistributed,
yr.YearDesc as Year,
ap.AppealDesc as Appeal
FROM
camDistributions di,
camPayments py,
camNamesV nm,
camPledges pl,
camAppeals ap,
camYears yr
WHERE
/* JOIN - to get payment at the payment date */
di.PaymentID = py.PaymentID
/* JOIN - to get the name of the Payor */
AND py.NameID = nm.NameID
/* JOIN - to get to the pledge distributed to */
AND di.PledgeID = pl.PledgeID
/* JOIN - to get the appeal desc */
AND pl.AppealID = ap.AppealID
/* JOIN - to get the year desc */
AND ap.YearID = yr.YearID
/* FILTER - to limit to given dates */
AND py.PaymentDate >= '01-JAN-2004'
AND py.PaymentDate <= '31-MAR-2004'
GROUP BY
yr.YearDesc,
ap.AppealDesc,
nm.Name