Hi I have a below query
with vcr as (
select b.CustNo,isnull(c.AMLRating,1) aml ,e.OrgType,d.ProfCd,
b.AcctType,
case
when b.AcctType in (43,41,47,85,80,81,66,44,11) then 'AOP'
when b.AcctType in (67,18,55,13,21,88,46,14,69,11,20,52,90,42,61,58,74,83,5,37,76,22,15,25,35,91,19,56) then 'Others'
when b.AcctType in (32,84,60,24,12) then 'Corporate'
when b.AcctType in (50,30,4,70,87,82) then 'Trust'
when b.AcctType in (8) then 'HUF'
when b.AcctType in (53) then 'NPO'
when b.AcctType in (71) then 'PEP'
WHEN b.AcctType IN (42,62,68,59,56,53,73,72,81,41,9,1,3,80,11,10,2,52,55,63,51,87) THEN 'IND'
end r1,
a.DrCr,a.FcyTrnAmt,x.CodeDesc org,y.CodeDesc profession,z.CodeDesc actype
from D009040 a inner join D009022 b on a.LBrCode=b.LBrCode and substring(a.MainAcctId,1,24)=substring(b.PrdAcctId,1,24)
left join D009012 c on b.CustNo=c.CustNo
left join D009013 e on b.CustNo=e.CustNo
left join D009012 d on b.CustNo=d.CustNo
left join D001002 x on e.OrgType=x.Code and x.CodeType=1162
left join D001002 y on d.ProfCd=y.Code and y.CodeType=1062
left join D001002 z on b.AcctType=z.Code and z.CodeType=1067
where a.CanceledFlag<>'C' and a.EntryDate between '17-sep-2018' AND '29-apr-2019'
--and b.CustNo=864838
and b.AcctType=8 and c.AMLRating=1
--and a.DrCr in ('D','C')
--order by a.DrCr
--and a.DrCr='D'
)
select r1,
count(distinct case when aml=1 then CustNo else 0 end) low_count,
count(distinct case when (aml=1 and DrCr='D') then CustNo else 0 end) low_debit_count
from vcr group by r1
if I run select * from vcr
I get 6 records
but when I run the above query I get 7 records
why ??
Please help