select count(*) cdrAccounts, sum( case when focusAccount = 'Y' then 1 else 0 end ) cdrFocusAccounts, sum( case when profileComplete = 'Y' then 1 else 0 end ) cdrAccountsComplete, sum( case when profileComplete = 'Y' and focusAccount = 'Y' then 1 else 0 end ) cdrFocusAccountsComplete from tbl_CDR_Distributors cdr inner join tbl_TER_Territories ter on ter.territoryId = cdr.cdr_territoryId and ter.ownerId = cdr.ownerId and ter.fsl_tablecode = cdr.fsl_tablecode where ter.territoryId = inner join tbl_FSPro_members m on m.fspro_userId = cdr.mfr_bsr_id and m.ownerId = cdr.ownerId and m.fsl_tablecode = cdr.fsl_tablecode where m.fspro_userId = and cdr.crmActive = 'Y' and cdr.ownerId = and cdr.fsl_tablecode =