where a.EMP_IDCARD = #{tSocialFundInfo.empIdcard} and
(
(a.SETTLE_DOMAIN_CODE = #{tSocialFundInfo.settleDomainCode} and a.SOCIAL_REDUCE_STATUS='2' and (a.SETTLE_DOMAIN_CODE_FUND is null or a.SETTLE_DOMAIN_CODE_FUND != #{tSocialFundInfo.settleDomainCode} or a.FUND_REDUCE_STATUS='2'))
or
(a.SETTLE_DOMAIN_CODE_FUND = #{tSocialFundInfo.settleDomainCode} and a.FUND_REDUCE_STATUS='2' and (a.SETTLE_DOMAIN_CODE is null or a.SETTLE_DOMAIN_CODE != #{tSocialFundInfo.settleDomainCode} or a.SOCIAL_REDUCE_STATUS='2'))
)
select count(1) from
(SELECT
a.EMP_IDCARD,a.HANDLE_STATUS social_status
FROM t_social_info a
where a.EMP_IDCARD = #{tSocialFundInfo.empIdcard} and a.SETTLE_DOMAIN = #{tSocialFundInfo.settleDomain} ORDER BY a.CREATE_TIME desc limit 1) a
left join
(SELECT
a.EMP_IDCARD,a.HANDLE_STATUS fund_status
FROM t_provident_fund a
where a.EMP_IDCARD = #{tSocialFundInfo.empIdcard} and a.SETTLE_DOMAIN = #{tSocialFundInfo.settleDomain} ORDER BY a.CREATE_TIME desc limit 1) b
on a.EMP_IDCARD=b.EMP_IDCARD
where
(a.social_status='3' and b.fund_status='3' )
or (a.social_status='3' and b.fund_status is null )
or (a.social_status is null and b.fund_status ='3' )