select t1.tarchives_adid,
       t1.tenterprise_userid,
       t3.fprovince,
       t3.fcity,
       t3.fcounty,
       t2.fname,
       count(0)                              fsharecount,
       MAX(t1.createdate)                    flastsharedate,
       count(distinct t4.tarchives_ad_shaid) fcustcount,
       SUM(t4.fvisitors)                     fvisitors
from tarchives_ad_share t1
         left join tenterprise_users t2 on t1.siteid = t2.siteid and t1.tenterprise_userid = t2.tenterprise_userid
         left join tagents t3 on t2.siteid = t3.siteid and t2.tagentsid = t3.tagentsid
         left join tarchives_ad_shareform t4 on t1.siteid = t4.siteid and t1.tarchives_adid = t4.tarchives_adid and
                                                t1.tenterprise_userid = t4.tenterprise_userid
where t1.siteid = $siteid$
  and t1.tarchives_adid = $tarchives_adid$ and (t1.tenterprise_userid in $tenterprise_userid$ or t3.fsaleruserid in $tenterprise_userid$)
group by t1.tarchives_adid, t1.tenterprise_userid, t3.fprovince, t3.fcity, t3.fcounty, t2.fname