select t1.tagents_costid, t1.fdate, sum(t2.famount) foutamount, sum(isnull(t3.forderamount, 0)) forderamount
from tagents_cost t1
         left join tagents_costmx t2
                   on t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid and t1.tagents_costid = t2.tagents_costid
         left join tcustomer_reception t3
                   on t1.siteid = t3.siteid and t1.tagentsid = t3.tagentsid and t3.ftype = 'ÏúÊÛ'
                       and convert(varchar(10), t1.fdate, 120) = convert(varchar(10), t3.fdate, 120)
where t1.siteid=$siteid$ and t1.tagentsid=$tagentsid$ and $where$
group by t1.tagents_costid, t1.fdate