Home » SQL & PL/SQL » SQL & PL/SQL » Please! How can I add these 2 amounts?
Please! How can I add these 2 amounts? [message #10236] Fri, 09 January 2004 10:56 Go to next message
Susan Gipson
Messages: 4
Registered: December 2003
Junior Member
For a view, I want to add the sum of all a person's contributions in a fisc. year and the sum of all of his/her spouse's contributions for that year (their contribution records are separate, under their own individual IDs). I need the total for each year, whether they both made contributions that year or not - it is very possible that one may have given during the year but the other did not.

Table: Gift-History
ID
Fisc Year
Gift Amt

I can link a person's ID to the spouse's ID through the Cross_Ref table.

Table: Cross-ref
ID
Code = 'SP' (for spouse)
Cross-ref ID

I have messed with this until I can't see straight. Any help would be greatly appreciated.

Susan
Re: Please! How can I add these 2 amounts? [message #10237 is a reply to message #10236] Fri, 09 January 2004 11:18 Go to previous messageGo to next message
sverch
Messages: 582
Registered: December 2000
Senior Member
Do spouses have something like common family_id? How you identify spouses?
Re: Please! How can I add these 2 amounts? [message #10238 is a reply to message #10237] Fri, 09 January 2004 12:22 Go to previous messageGo to next message
Susan Gipson
Messages: 4
Registered: December 2003
Junior Member
Through the Cross-ref table. It has the ID of the person, the code of 'SP' (indicates a spouse relationship), and the Cross-Ref ID is the spouse's ID.
Re: Please! How can I add these 2 amounts? [message #10239 is a reply to message #10236] Fri, 09 January 2004 13:06 Go to previous message
sverch
Messages: 582
Registered: December 2000
Senior Member
Susan,

I have to run and cannot write a query for you right now, but I think you can build inline views (SELECT FROM (SELECT... for "prime contributor"), (select... for spouse )) and in the main query compute contributions A and B. If you have reference id it should not be hard...

Anyway, it is always easier to help when people sent sample data and desired result...
Previous Topic: Find the Parent table and all its related children
Next Topic: Oracle's trigger on rental_property
Goto Forum:
  


Current Time: Fri Apr 26 12:07:18 CDT 2024