sql 统计类语句

1、统计每月的成交量,按照逆序排序(2013年以来的每月销量,oracle实现)
select to_char(t.payment_time,'yyyy-MM'),count(t.id) as 笔数,sum(t.payment_amount) as 月总金额 from business_journal t where t.payment_type='11' and t.err_code='00' and
to_date(to_char(t.payment_time,'yyyy-MM-dd'),'yyyy-MM-dd')>to_date('2012-12-31','yyyy-MM-dd') group by to_char(t.payment_time,'yyyy-MM') having count(t.id)>0
order by to_char(t.payment_time,'yyyy-MM') desc ;

猜你喜欢

转载自stevenjohn.iteye.com/blog/2032399
今日推荐