L
Lis B.
Hi. I have two tables, Contacts and Donors. The Donors table lists each
donation by date and amount with a foreign key that refers to the Contact ID
in the Contacts table. I want to write a query that tells me how many
people who are repeat donors increased the amount of their donation. So I
need to compare their last donation (by date) with the next to last
donation. I don't care about any donations previous to the last two
donations.
I've written this query but it's not really giving me what I want. What I
really want is one line for each person whose most recent donation is more
than their previous donation. I want their names and the date of the most
recent donation and the amounts of the most recent and the previous.
Can anyone help me?
Here's what I've written which is returning too many rows:
Select C.LastName, C.FirstName, C.[ID], max(D.DateofDonation) as
DonationDate, D.Amount
(select max(D1.DateofDonation) from Donations D1 where D1.[id] = C.[id]
and d1.dateofdonation < d.dateofdonation) as EarlierAmount
from Contacts C right join Donations D
on C.[id] = D.[id]
group by C.LastName, C.FirstName, C.[ID], D.Amount, D.DateofDonation
Thanks
Lis B.
donation by date and amount with a foreign key that refers to the Contact ID
in the Contacts table. I want to write a query that tells me how many
people who are repeat donors increased the amount of their donation. So I
need to compare their last donation (by date) with the next to last
donation. I don't care about any donations previous to the last two
donations.
I've written this query but it's not really giving me what I want. What I
really want is one line for each person whose most recent donation is more
than their previous donation. I want their names and the date of the most
recent donation and the amounts of the most recent and the previous.
Can anyone help me?
Here's what I've written which is returning too many rows:
Select C.LastName, C.FirstName, C.[ID], max(D.DateofDonation) as
DonationDate, D.Amount
(select max(D1.DateofDonation) from Donations D1 where D1.[id] = C.[id]
and d1.dateofdonation < d.dateofdonation) as EarlierAmount
from Contacts C right join Donations D
on C.[id] = D.[id]
group by C.LastName, C.FirstName, C.[ID], D.Amount, D.DateofDonation
Thanks
Lis B.