select t1.tagentsid,t2.fagentnum,t2.fagentname,t2.fprovince,t2.fcity,t2.fcounty,count(distinct tsaleeventid)feventcount,
       count(t1.tcustomer_receptid)fordercount,convert(int,avg(t1.forderamount))forderamount from DSBCRM..tcustomer_reception t1
inner join DSBCRM..tagents t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid
where t1.ftype='ÏúÊÛ' and t1.siteid=$siteid$ and
convert(varchar(7),t1.fdate,120)>=$fbegmonth$ and convert(varchar(7),t1.fdate,120)<=$fendmonth$
and t1.fsaleevent is not null
group by t1.tagentsid,t2.fagentnum,t2.fagentname,t2.fprovince,t2.fcity,t2.fcounty
