Monday, January 14, 2013

Aggregate Functions

--aggregate functions
use CommunityAssist

Select Count(*) as [Number of Donations ]
From Donation
Where DonationAmount > 500


Select Count(*) From PersonAddress
Select Count(Apartment) From PersonAddress

Select sum(DonationAmount) as total 
From Donation
Where DonationAmount > 500

Select Round(Avg(DonationAmount),2) as Average
From Donation

Select Max(DonationAmount) as Biggest, 
Min(donationAmount) as smallest
From Donation

Select Max(DonationDate) From Donation

Select PersonKey, Max(DonationAmount) as biggest
From donation
Group by PersonKey

Select Max(Lastname) From Person


Select Year(DonationDate) as [Year],
Month(DonationDate) as [Month],
'$' + Cast(Sum(donationAmount)as Nvarchar) as total
From Donation
Where Month(donationDate)>2
Group by Year(DonationDate), Month(donationDate)
Having Sum(donationAmount) > 6000

Select Month(DonationDate), avg(DonationAmount) 
From Donation
Group by Month(donationDate)
having Avg(DonationAmount)>500

Select DonationAmount from Donation
order by DonationAmount 

Select avg(DonationAmount)From Donation
Select avg(Distinct DonationAmount) from Donation

Select Count(PersonKey) From Donation
Select count (distinct PersonKey) as Donors from Donation

Select Distinct DonationAmount From Donation

Select DonationAmount,Count(donationAmount) [number of Donations]
From Donation
Group by DonationAmount


No comments:

Post a Comment