Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tbc
Starting Member
3 Posts |
Posted - 2006-12-04 : 22:50:23
|
| I don't know why the last topic is locked, but here is the situation more detailed.I know that the group by is the answer for my last question.But the situation is sadly not this easy:We have a Donortype table and it looks like this:D DONORTARGETQ1 DONORTARGETQ2 DONORTARGETQ3 DONORTARGETQ4- ------------- ------------- ------------- -------------C 400 400 500 500F 300 350 400 500I 125 150 200 2753 rows selected.The first column is called donortype. That's what we have to use.The contribution table looks like this:CONTRIBUT DONORID CONTRIBUTIONAMOUNT PROGRAMNAME MEMBERNUMB--------- ---------- ------------------ ------------------------------ ----------03-JAN-06 2 200 Basic Research 507-JAN-06 3 150 Applied Research 327-JAN-06 7 50 Teaching Programs 105-FEB-06 6 100 International Programs 223-FEB-06 2 50 International Programs 103-MAR-06 1 100 Basic Research 630-MAR-06 5 75 Basic Research 115-APR-06 6 50 Teaching Programs 409-MAY-06 4 100 Applied Research 214-MAY-06 7 100 International Programs 529-MAY-06 7 100 Applied Research 511-JUN-06 5 50 Teaching Programs 518-JUN-06 6 75 Applied Research 223-JUN-06 3 50 Basic Research 310-JUL-06 1 100 Teaching Programs 316-JUL-06 4 100 International Programs 222-JUL-06 6 75 Applied Research 415-AUG-06 5 60 Applied Research 123-AUG-06 2 150 International Programs 109-SEP-06 3 175 Applied Research 618-SEP-06 6 150 Teaching Programs 201-OCT-06 2 80 International Programs 513-OCT-06 1 50 Basic Research 630-OCT-06 5 25 Applied Research 111-NOV-06 4 100 Teaching Programs 424-NOV-06 2 100 Applied Research 510-DEC-06 7 200 Basic Research 120-DEC-06 3 85 International Programs 628 rows selected.We have the DonorID and the ContributionAmount here.We also have a Donor table:DONORID DONORNAME D DONORPROJECTION---------- ------------------------------ - ---------------1 Crabtree I 502 Genetix C 1003 Marlo I 554 Mervis F 605 Orange Computers C 506 Roper Foundation F 707 Keltron, Inc. C 857 rows selected.The third column is DonorType as well.What I have to create is something like thisDonorType ContributionAmountI 100F 300C 250Where the 100 is the sum of ContributionAmounts performed by DonorID-s which have a DonorType Iand 300 is the sum of ContributionAmounts performed by DonorID-s which have a DonorType Fand so on...(the numbers are made up, they are probably not correct...)My idea was that let's create a view with DonorID and sum(ContributionAmount) grouped by DonorID.Than join this view with the DonorType table, and create a view which contains DonorId, DonorType and sum(ContributionAmount) from the first view.And what now?! HOw do you group this by DonorType? |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2006-12-04 : 23:03:14
|
| Your last topic was locked because we don't do peoples homework for them.If you are studying a degree that puts you into this industry, and you don't have the understanding or the ability to learn this so that you end up in a situation that it's the night before your assignment is due and you don't have the faintest clue how to do the work, then us giving you the answer isn't going to help you, your class, or our profession.Damian"A foolish consistency is the hobgoblin of little minds." - Emerson |
 |
|
|
|
|
|