select sum(t.forderamount)       as forderamount,--销售额
       SUM(t.fnewordercount)     as fnewordercount,--新增订单数
       SUM(t.favgorderamount)    as favgorderamount,--平均客单值
       SUM(t.freturncount)       as freturncount, --退单数
       SUM(t.freturnamount)      as freturnamount, --退单金额
       SUM(t.freceivablesamount) as freceivablesamount,--应收金额
       SUM(t.freceivablescount)  as freceivablescount--应收单数
from (
         select sum(forderamount)                                                  as forderamount,
                count(0)                                                           as fnewordercount,
                convert(int, isnull(AVG(forderamount), 0))                         as favgorderamount,
                0                                                                  as freturncount,
                0                                                                  as freturnamount,
                sum(freceivablesamount)                                            as freceivablesamount,
                sum(case when isnull(freceivablesamount, 0) > 0 then 1 else 0 end) as freceivablescount
         from tcustomer_reception t1
         where siteid = $siteid$
           and tagentsid = $tagentsid$
           and ftype = '销售'
           and convert (varchar (7)
             , createdate
             , 120) = convert (varchar (7)
             , getdate()
             , 120)
           and $where$
         union all
select 0                                                                   as forderamount,
       0                                                                   as fnewordercount,
       0                                                                   as favgorderamount,
       count(0)                                                            as freturncount,
       sum(forderamount)                                                   as freturnamount,
       - sum(freceivablesamount)                                           as freceivablesamount,
       -sum(case when isnull(freceivablesamount, 0) > 0 then 1 else 0 end) as freceivablescount
from tcustomer_reception t1
where siteid = $siteid$
  and tagentsid = $tagentsid$
  and ftype = '销售'
  and fstatus = '退单'
  and convert (varchar (7)
    , closedate
    , 120) = convert (varchar (7)
    , getdate()
    , 120)
  and $where$
    ) t