Click here to Skip to main content
11,805,035 members (66,502 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# MySQL

in my application i wanted to store donor details ,so i have created a donor table with some field like donor name, amount etc.. same donor can donate amounts any time. so i wanted to get the total amounts donated by each donors is there any way?

Posted 27-Mar-13 21:54pm
Edited 27-Mar-13 21:55pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need the SUM function and a GROUP BY clause.
Something like
SELECT donor, SUM(donation) as TotalAmount
From MyTable
Group By donor
ginnas at 28-Mar-13 5:25am
Thanks Hiller
it helped me truely, thank you very much
i have few more doubts,in the same table i have to get 1-the donors who donating more than 10000 in year
2-donors who are not donating during the past 2 years
in my table i have one field for storing the donating date

so how can we do this ?

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Well, you need to use the aggregate function to get the total amount.
And you need to use the Group by clause to group the total amount from each donor.

select donor, sum(amount) from tbl_x group by donor

that's all.
I hope this helps you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 305
1 Sergey Alexandrovich Kryukov 268
2 CPallini 210
3 Richard Deeming 190
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100