select t1.tenterprise_userid,t3.fname fsaler, t1.fname, t2.fprovince, t2.fcity, t2.fcounty, t1.fphonenumber,MAX(t4.createdate) as flastreadtime,count(distinct t4.tarchives_userdaid)freadcount,
       sum(DATEDIFF(MINUTE,t4.createdate,t4.closedate)) freadtimes,count(t6.tattachment_downid)fdownloadtimes
from tenterprise_users t1
            inner join tagents t2 on t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid
            inner join tenterprise_users t3 on t2.siteid = t3.siteid and t2.fsaleruserid = t3.tenterprise_userid
            left join tarchives_userdata t4 on t1.siteid=t4.siteid and t1.tenterprise_userid=t4.tenterprise_userid and t4.tarchivesid=$tarchivesid$
       inner join tattachment t5 on t1.siteid=t5.siteid and t5.ownertable='tarchives' and t4.tarchivesid=t5.ownerid
       inner join tattachment_downlog t6 on t5.siteid=t6.siteid and t5.tattachmentid=t6.tattachmentid and t6.tenterprise_userid=t1.tenterprise_userid
where t1.siteid = $siteid$ and t1.fisadministrator=1 and t1.fusertype = '¾­ÏúÉÌ'
group by t1.tenterprise_userid,t3.fname , t1.fname, t2.fprovince, t2.fcity, t2.fcounty, t1.fphonenumber