select t1.fname,t1.fcommunity,t1.fdate,t1.changedate,t1.fcustaction,t1.tcustomer_receptid from tcustomer_reception t1
inner join tcustomer t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid and t1.tcustomerid=t2.tcustomerid
where t1.ftype='½Ó´ý' and t1.siteid=$siteid$ and t1.tagentsid=$tagentsid$  and $where$
and exists(
    select MAX(tcustomer_receptid)maxid from tcustomer_reception where ftype='ÏúÊÛ'
  and siteid=t1.siteid and tagentsid=t1.tagentsid and tcustomerid=t1.tcustomerid
    having t1.tcustomer_receptid>isnull(MAX(tcustomer_receptid),0)
)