select t1.tenterprise_userid,
       t1.siteid,
       t4.fagentnum,
       t4.fagentname,
       t4.fprovince,
       t4.fcity,
       t4.fcounty,
       t1.fname,
       t1.fphonenumber,
       t1.fisadministrator,
       t1.frole,
       t1.fsex,
       convert(varchar(10), t3.fdate, 120) as flastlogintime,
       t6.fbegdate,
       t6.fenddate
from tenterprise_users t1
         left join (select max(tuserrequestlogid) tuserrequestlogid, siteid, tenterprise_userid
                    from tuserrequestlog
                    group by siteid, tenterprise_userid) t2
                   on t1.siteid = t2.siteid and t1.tenterprise_userid = t2.tenterprise_userid
         left join tuserrequestlog t3 on t2.siteid = t3.siteid and t2.tenterprise_userid = t3.tenterprise_userid and
                                         t2.tuserrequestlogid = t3.tuserrequestlogid
         inner join tagents t4 on t1.siteid = t4.siteid and t1.tagentsid = t4.tagentsid
         left join (select max(tpayinfoid) tpayinfoid, siteid, tagentsid from tpayinfo group by siteid, tagentsid) t5
                   on t1.siteid = t5.siteid and t1.tagentsid = t5.tagentsid
         left join tpayinfo t6
                   on t5.siteid = t6.siteid and t5.tagentsid = t6.tagentsid and t5.tpayinfoid = t6.tpayinfoid
where t1.fusertype = '¾­ÏúÉÌ' and t1.fname is not null and t1.siteid =$siteid$ and $where$