select ROW_NUMBER()over(order by t3.fsubmitcount desc) as row,
       t1.fname,
       t3.fsubmitcount,
       t2.fname as fsaler
from tagents_workers t1
         left join tenterprise_users t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid and t1.createuserid=t2.tenterprise_userid
         left join (
    select t1.tenterprise_userid, count(0) as fsubmitcount from tagents_workers t1
                                                                    inner join tagents_workersubmit t2 on t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid and t1.tenterprise_userid = t2.tenterprise_userid
    where t1.siteid =$siteid$ and t1.tagentsid=$tagentsid$ and fiscooperation=1 and $where$ and $where2$
    group by t1.tenterprise_userid
) t3 on t1.tenterprise_userid = t3.tenterprise_userid
where t1.siteid =$siteid$ and t1.tagentsid=$tagentsid$ and fiscooperation=1 and $where$