select t1.tagentactivitiesid,
       t1.ftitle,--标题
       t1.fnotes,
       t1.fphonenumber,
       t1.fbegdate,--开始日期
       t1.fenddate,--结束日期
       t1.fstatus,--活动状态
       t1.fsaler1rewardamount1,--一级推广人拉新奖励
       t1.fsaler1rewardamount2,--一级推广人线索奖励
       SUM(t3.fremuneration) as                    fremuneration,--我的奖励
       count(distinct t2.tagentactivities_shareid) fsharecount,--分享次数
       sum(t3.fcustcount)    as                    fcustcount,--流量，阅读人数
       sum(t3.fformcount)    as                    fformcount--线索，意向客户数
from tagentactivities t1
         left join tagentactivities_share t2 on t1.siteid = t2.siteid and t1.tagentactivitiesid = t2.tagentactivitiesid and t2.fsaler2id =$tenterprise_userid$
    left join (
    select tt1.tagentactivities_shareid, count (0) as fcustcount, 0 as fformcount, sum (tt2.famount) fremuneration from tagentactivities_share tt1
    inner join tagentactivities_cust tt2 on tt1.tagentactivitiesid=tt2.tagentactivitiesid and tt1.tagentactivities_shareid=tt2.tagentactivities_shareid
    where tt1.siteid=$siteid$ and tt1.tagentactivitiesid=$tagentactivitiesid$ and tt1.fsaler2id=$tenterprise_userid$ group by tt1.tagentactivities_shareid
    union all
    select tt1.tagentactivities_shareid, 0 as fcustcount, count (0) as fformcount, sum (tt2.famount) fremuneration from tagentactivities_share tt1
    inner join tagentactivities_form tt2 on tt1.tagentactivitiesid=tt2.tagentactivitiesid and tt1.tagentactivities_shareid=tt2.tagentactivities_shareid
    where tt1.siteid=$siteid$ and tt1.tagentactivitiesid=$tagentactivitiesid$ and tt1.fsaler2id=$tenterprise_userid$ group by tt1.tagentactivities_shareid
    ) t3
on t2.tagentactivities_shareid=t3.tagentactivities_shareid
where t1.siteid =$siteid$ and t1.tagentactivitiesid=$tagentactivitiesid$
group by t1.tagentactivitiesid,
    t1.ftitle,
    t1.fnotes,
    t1.fphonenumber,
    t1.fbegdate,
    t1.fenddate,
    t1.fstatus,
    t1.fsaler1rewardamount1,
    t1.fsaler1rewardamount2
