select t1.tagentactivitiesid,
       t1.tenterprise_userid,
       t1.ftitle,
       t1.checkby,
       t1.checkdate,
       t4.fagentname,
       t1.fstatus,
       t1.siteid,
       count(t2.tagentactivities_shareid) fsharecount,--分享次数
       SUM(t3.fvisitors)                  freadcount,--浏览次数
       count(t3.tagentactivities_custid)  fcustcount--流量，阅读人数
from tagentactivities t1
         left join tagentactivities_share t2 on t1.siteid = t2.siteid and t1.tagentactivitiesid = t2.tagentactivitiesid
         left join tagentactivities_cust t3 on t1.siteid = t3.siteid and t1.tagentactivitiesid = t3.tagentactivitiesid
         left join tagents t4 on t1.siteid = t4.siteid and t1.tagentsid=t4.tagentsid
where exists(select tpromotersid
             from tpromoters
             where tpromoters.siteid = t1.siteid
               and tpromoters.tagentsid = t1.tagentsid
               and tpromoters.fsaler2id =$tenterprise_userid$ and tpromoters.fstatus=1)
group by t1.tagentactivitiesid, t1.tenterprise_userid, t1.ftitle,
         t1.checkby, t1.checkdate, t4.fagentname, t1.fstatus,t1.siteid