日期:2014-05-16 浏览次数:20760 次
select o.orgid,date_format(o.orderdate,'%Y'),count(*),sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)as totalmoney,sum(case when o.payamount is not NULL then o.payamount else '0.00' end) as paymoney, (sum(case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)-sum(case when o.payamount is not NULL and (case when o.finalamount!='0.00' then o.finalamount else o.contractamount end)!='0.00' then o.payamount else '0.00' end)) as nopaymoney from htglview o where 1=1 and o.contractState in (5,8,9,10,11) and o.contractType='0' group by o.orgid, date_format(o.orderdate,'%Y') order by o.orgid,date_format(o.orderdate,'%Y')