select tagents_purchaseid,fyear,fmonth,t1.tagentsid,t2.fagentname,t1.famount,t1.changedate from tagents_purchase t1
inner join tagents t2 on t1.siteid =t2.siteid and t1.tagentsid=t2.tagentsid
where t1.siteid=$siteid$ and t2.fsaleruserid in $fsaleruserid$ and $where$