I have researched and found questions/answers like my issue here but nothing I can find exactly fits.
SELECTING with multiple WHERE conditions on same column --- This link is VERY close but still doesn't work for my issue.
Problem: I have a table that houses Payment Methods and Payment Status (blank status is OK)
SEL_PRO_PMTMETHOD_PK SEL_PROFILE_DETAIL_FK PMT_TYPE PMT_STATUS
43827 342997 EFT G
43828 342997 EFT P
43829 342997 RCC
43826 342997 EFT
43776 342922 EFT
43777 342922 EFT G
43778 342922 EFT P
I need to develop unique output by SEL_PROFILE_DETAIL_FK depending on whether it has ONLY EFTs entries, ONLY RCC entries, or BOTH EFT and RCC entries.
I figured out the easy stuff for ONLY EFT and ONLY RCC
But I need to be able to tell if there is BOTH EFT and RCC entries in the FK grouping.
My code so far:
SELECT pmt_type
FROM sel_pro_pmtmethod
WHERE sel_profile_detail_fk = '342997'
AND pmt_type IN ('EFT', 'RCC')
GROUP BY pmt_type
HAVING COUNT(distinct pmt_type) >= 1
This code is returning back pmt_type for both sets of data above. It doesn't matter if it has BOTH EFT and RCC, or just the EFT.
I have changed the HAVING COUNT clause to be "= 2" but that returns nothing because the count of RCCs = 1 and the EFTs = 3.
But what I need is for this WHERE / GROUP BY / HAVING scenario to be true is if there is an EFT AND RCC entry in the grouping. If one is missing then it fails.