So i have a temporary table that I need to populate with the records that have to deal with enrollment history
I work with a dataset that looks like this:
sccphidsid enroll_date disenroll_date status
abc123x 2009-01-01 2010-31-12 0
abc123x 2011-01-01 null 0
abc123x 2011-03-01 2012-01-01 0
So I need it to return all records with the same sccphidsid and return them including the null and not null values.
The conditions it has to meet are
Current Solution:
select *, count(disenroll_date is null)
from enrollment _test
where Status = 0
group by Sub_Client_Cd, Policy_Holder_ID, Suffix_ID
having count(disenroll_date is null) > 1;
However this is returning too many records, is there a way to isolate this query down, maybe simpler, that can prevent this from returning too many records by constraints or parameters?
Thanks all
SELECT Sub_Client_Cd, Policy_Holder_ID, Suffix_ID,
SUM(CASE WHEN disenroll_date IS NULL THEN 1 ELSE 0 END) AS NullDateCount,
SUM(CASE WHEN disenroll_date IS NOT NULL THEN 1 ELSE 0 END) AS NotNullDateCount
FROM enrollment_test
WHERE Status = 0
GROUP BY Sub_Client_Cd, Policy_Holder_ID, Suffix_ID
HAVING COUNT(*) > 1;
Actually this took care of it... Thanks anyways.
select *, count(disenroll_date is null) from enrollment_test
where Status = 0
and disenroll_date is null
group by Sub_Client_Cd, Policy_Holder_ID, Suffix_ID
having count(disenroll_date is null) > 1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.