Click here to Skip to main content
11,930,449 members (55,194 online)
Rate this:
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 22:54pm
Edited 27-Mar-13 22: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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.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