select t1.tenterprise_userid,t4.fname fsaler, t2.fname, t3.fprovince, t3.fcity, t3.fcounty, t2.fphonenumber,flastreadtime,count(t5.tnotice_userdataid)freadcount,
       sum(DATEDIFF(MINUTE,t5.createdate,t5.closedate)) freadtimes,count(t7.tattachment_downid)fdownloadtimes
from tnotice_users t1
       inner join tenterprise_users t2 on t1.siteid = t2.siteid and t1.tenterprise_userid = t2.tenterprise_userid
       inner join tagents t3 on t2.siteid = t3.siteid and t2.tagentsid = t3.tagentsid
       inner join tenterprise_users t4 on t3.siteid = t4.siteid and t3.fsaleruserid = t4.tenterprise_userid
       inner join tnotice_userdata t5 on t1.siteid=t5.siteid and t1.tnoticeid=t5.tnoticeid and t1.tenterprise_userid=t5.tenterprise_userid
       inner join tattachment t6 on t1.siteid=t6.siteid and t6.ownertable='tnotice' and t1.tnoticeid=t6.ownerid
       inner join tattachment_downlog t7 on t6.siteid=t7.siteid and t6.tattachmentid=t7.tattachmentid and t7.tenterprise_userid=t1.tenterprise_userid
where t1.siteid = $siteid$ and t1.tnoticeid = $tnoticeid$ and t1.flastreadtime is not null
group by t1.tnotice_usersid,t1.tenterprise_userid,t4.fname,t2.fname,t3.fprovince,t3.fcity,t3.fcounty,t2.fphonenumber,flastreadtime