Hey guys,
I have the following query:
Code:
SELECT distinct PR0.RECIP_SSN_NBR,
PR01.AGTY_ID_NM,
PR0.RECIP_RETIR_DT,
PR0.AGTY_ID_CD,
PR02.ANTY_PYMT_TOT_AMT
FROM DSNP.PR01_T_RECIP_SYS PR0,
DSNP.PR01_T_EMPR PR01,
DSNP.PR01_T_ANTY_PYMT PR02
WHERE PR0.AGTY_ID_CD=PR01.AGTY_ID_CD
AND PR0.RECIP_SSN_NBR=PR02.RECIP_SSN_NBR
AND PR0.AGTY_SYS_CD = 'TAPERS'
AND PR02.ANTY_PYMT_DT BETWEEN '2007-07-01' AND '2008-06-30'
They want to see the employee's most recent PR02.ANTY_PYMT_TOT_AMT. The problem is the results are displaying numerous records for the same SSN if they have different TOT_AMT's within my date range.
How can I modify the query to only pull the most recent payment amount going by the PR02.ANTY_PYMT_DT field?
Ex. SSN DATE PAYMENT
3334455 08/12/07 234.44
3334455 09/12/07 123.44
I want the query to display:
3334455 09/12/07 123.44
Thanks!