select t1.tsubmiteditmodelid,
       t1.ftitle,
       t1.fbegdate,
       t1.fenddate,
       t1.checkdate,
       count(distinct t2.tenterprise_userid)                              as frequireqty,
       count(distinct case when t2.fstatus = 'جل½»' then t2.tenterprise_userid  else null end) as fsubmitqty,
       t1.fisnotlimittimes
from DSBCRM..tsubmiteditmodel t1
       inner join DSBCRM..tsubmitedit t2 on t1.siteid = t2.siteid and t1.tsubmiteditmodelid = t2.tsubmiteditmodelid
       inner join DSBCRM..tagents t3 on t2.siteid=t3.siteid and t2.tagentsid=t3.tagentsid
where t1.fstatus = '·¢²¼'
  and t1.siteid =$siteid$
  and (t3.fsaleruserid in $tenterprise_userid$
) and $where$
group by t1.tsubmiteditmodelid, t1.ftitle, t1.fbegdate, t1.fenddate, t1.checkdate,t1.fisnotlimittimes