I have two tables ‘Receipt Table:’ and ‘Person Table:’
I need to find the result set for these values
SUM amount, MAXIMUM amt paid as of today, MAXIMUM amt paid_DATE as of today,
RECENT amt paid as of today, RECENT amt paid_DATE as of today.
Here is the Tabluler format below.
RECEIPT TABLE:
ReceiptID Receipt_Date AmountPaid PersonID
R001 1/1/2011 $50 P003
R002 1/2/2011 $20.20 P001
R003 1/2/2011 $35 P005
R004 1/4/2011 $17 P002
R005 1/10/2011 $89.20 P003
R006 1/11/2011 $10 P001
R007 1/11/2011 $9.15 P007
R008 1/12/2011 $5.45 P002
R009 1/20/2011 $65 P006
R010 1/23/2011 $20 P004
R011 1/29/2011 $10 P003
PERSON TABLE:
PersonID PersonName
P001 A_person
P002 B_person
P003 C_person
P004 D_person
P005 E_person
P006 F_person
P007 G_person
P008 H_person
OUTPUT RESULT:
PersonID PersonName Sum(Amtpaid) RECENT(AmountPaid) RECENT(Amtpaid_ReceiptDate) Max (Amt Receipt_paid as of today) Max (amt receipt paid Date as of today)
P001 A_Person $30.20 $10 1/11/2011 $20.20 1/2/2011
P002 B_person $22.45 $5.45 1/12/2011 $17 1/4/2011
P003 C_person $149.20 $10 1/29/2011 $89.20 1/10/2011
P004 D_person $20 $20 1/23/2011 $20 1/23/2011
P005 E_person $35 $35 1/2/2011 $35 1/2/2011
P006 F_person $65 $65 1/20/2011 $65 1/20/2011
P007 G_person $9.15 $9.15 1/11/2011 $9.15 1/11/2011
I’m not on a computer where I can test this code, but maybe you can try this:
Anyway, if you use the code before, you should be aware that it returns the
MINReceiptDate in case that the MaxAmountPaid is repeated (meaning that it has 2 records that are the same amount and the MaxAmountPaid).