select t1.tagentsid,t1.fagentshortname,t2.fname as fsaler,t1.fprovince,t1.fcity,t1.fcounty,
       count(distinct t3.tagents_workersid)fworkercount,
       count(distinct t4.tagents_workersubmitid)fmonthsubmitcount,
       count(distinct t5.tagents_workersubmitid)fyearsubmitcount,
       count(distinct t6.tagents_workersubmitid)as fsubmitcount from tagents t1
left join tenterprise_users t2 on t1.siteid=t2.siteid and t1.fsaleruserid=t2.tenterprise_userid
left join tagents_workers t3 on t1.siteid=t3.siteid and t1.tagentsid=t3.tagentsid and t3.fiscooperation=1
left join tagents_workersubmit t4 on t1.siteid=t4.siteid and t1.tagentsid=t4.tagentsid and t4.fismodify=0 and convert(varchar(7),t4.createdate,120)=convert(varchar(7),GETDATE(),120)
left join tagents_workersubmit t5 on t1.siteid=t5.siteid and t1.tagentsid=t5.tagentsid and t5.fismodify=0 and year(t5.createdate)=year(GETDATE())
left join tagents_workersubmit t6 on t1.siteid=t6.siteid and t1.tagentsid=t6.tagentsid and t6.fismodify=0
where t1.siteid=$siteid$
group by t1.tagentsid,t1.fagentshortname,t2.fname,t1.fprovince,t1.fcity,t1.fcounty