select SUM(t.fuseronlinecount)  as fuseronlinecount,
       SUM(t.fagentusedcount)   as fagentusedcount,
       SUM(t.fdownloadcount)    as fdownloadcount,
       SUM(t.fagentnousedcount) as fagentnousedcount
from (
       select count(0) fuseronlinecount, 0 fagentusedcount, 0 fdownloadcount, 0 fagentnousedcount
       from tuserrequestlog
       where siteid=$siteid$ and flastrequestdate > DATEADD(MINUTE, -30, getdate())
       union all
       select 0, count(0), 0, 0
       from tagents t1
       where siteid=$siteid$ and exists(select * from tuserrequestlog t2 where t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid and convert(varchar(10),t2.fdate,120)=convert(varchar(10),getdate(),120))
       union all
       select 0, 0, count(0), 0
       from tattachment_downlog
       where siteid=$siteid$ and convert(varchar(10), createdate, 120) = convert(varchar(10), getdate(), 120)
       union all
       select 0, 0, 0, count(0)
       from tagents t1
       where siteid=$siteid$ and not exists(select * from tuserrequestlog t2 where t1.siteid = t2.siteid and t1.tagentsid = t2.tagentsid and convert(varchar(10),t2.fdate,120)=convert(varchar(10),getdate(),120))
     ) t