Hey guys,
I am stuck trying to work out the logic for this query request. The request has two criterias:
1. Find all members who have a credit date of '1998-06-30' or later.
2. Out of those results, only display members who have a contribution amount in their entire history that is greater than zero.
Example of table (dummy data):
SSN Credit Date Credit Amount
11122 1955-04-04 0.00
11122 1966-05-02 123.00
11122 1998-06-30 0.00
22344 1978-06-04 23.00
22344 1988-06-03 0.00
As you can see, there are multiple credit dates and amounts for each social. 22344 would not be included in my results because he does have a 1998 date.
I came up with this, but I'm not confident that it is right:
What do you guys think? Thanks!
I am stuck trying to work out the logic for this query request. The request has two criterias:
1. Find all members who have a credit date of '1998-06-30' or later.
2. Out of those results, only display members who have a contribution amount in their entire history that is greater than zero.
Example of table (dummy data):
SSN Credit Date Credit Amount
11122 1955-04-04 0.00
11122 1966-05-02 123.00
11122 1998-06-30 0.00
22344 1978-06-04 23.00
22344 1988-06-03 0.00
As you can see, there are multiple credit dates and amounts for each social. 22344 would not be included in my results because he does have a 1998 date.
I came up with this, but I'm not confident that it is right:
Code:
SELECT A.MBR_SSN_NBR, A.MBR_HIST_SVC_CR_DT, A.HIST_CATEG_CD,
A.MBR_CNTRB_AMT
FROM DSNP.PR01_T_MBR_HIST A
WHERE A.AGTY_ID_CD = '00499'
AND A.HIST_CATEG_CD = '10'
AND A.MBR_CNTRB_AMT > 0.0
AND EXISTS (SELECT 1 FROM DSNP.PR01_T_MBR_HIST Z WHERE Z.MBR_SSN_NBR = A.MBR_SSN_NBR AND Z.MBR_HIST_SVC_CR_DT >= '1998-06-30' )
What do you guys think? Thanks!