Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL
hello,
 

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?
 
Thanks
Ginnas
Posted 27-Mar-13 22:54pm
ginnas457
Edited 27-Mar-13 22:55pm
v2
Rate this: bad
good
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
  Permalink  
Comments
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 ?
 
Regards
Ginnas
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
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