Hey guys,
SQL keeps complaining that A.STATUS is not valid in the context with the GROUP BY.
Am I doing something wrong here?
SQL keeps complaining that A.STATUS is not valid in the context with the GROUP BY.
Am I doing something wrong here?
Code:
SELECT distinct a.mbr_ssn_nbr,
b.mbr_f_nm,
b.mbr_l_nm,
sum(c.mbr_svc_cr_yy_ct) as TOTAL_YEARS,
sum(c.mbr_svc_cr_mm_ct) as TOTAL_MONTHS,
a.mbr_stat_cd,
CASE
when a.mbr_stat_cd = 'A' then 'ACTIVE'
when a.mbr_stat_cd = '2' then 'INACTIVE'
end as STATUS,
a.mbr_sys_cd,
a.mbr_vest_ind
FROM dsnp.pr01_t_mbr_sys a,
dsnp.pr01_t_mbr b,
dsnp.pr01_t_mbr_hist c
WHERE a.MBR_SSN_NBR=b.MBR_SSN_NBR
AND a.MBR_SSN_NBR=c.MBR_SSN_NBR
AND a.MBR_STAT_CD IN ('A')
AND b.MBR_RECIPR_SYS_IND = 'Y'
AND not exists (select c.recip_ssn_nbr from dsnp.pr01_t_recip_sys c where c.recip_ssn_nbr = a.mbr_ssn_nbr and c.benef_stat_cd = 'DI')
AND hist_categ_cd = '10'
group by
a.mbr_ssn_nbr,
b.mbr_f_nm,
b.mbr_l_nm,
a.STATUS,
a.mbr_stat_cd,
a.mbr_sys_cd,
a.mbr_vest_ind