oracle 按每天,每月,每日,年查询数据量

select * from tablename md 
//按天统计
select to_char(md.createtime,'yyyy-mm-dd') as xx, count(md.billmaindataid) as 每天操作数量, sum(md.naturalamount)
from  tablename md
where md.currentstate != 22
group by to_char(md.createtime,'yyyy-mm-dd')
order by xx desc

 //按自然月统计 
select to_char(md.createtime,'yyyy-mm') as xx, count(md.billmaindataid) as 每天操作数量, sum(md.naturalamount)
from  tablename md
--where md.currentstate != 22
--and md.createtime between to_date('2014-01','yyyy-mm') and to_date('2014-12','yyyy-mm') 
group by to_char(md.createtime,'yyyy-mm')
order by xx desc

//按年统计
select to_char(md.createtime,'yyyy') as xx, count(md.billmaindataid) as 每天操作数量, sum(md.naturalamount)
from  tablename md
--where md.currentstate != 22
group by to_char(md.createtime,'yyyy')
order by xx desc
 
//按季统计 
select to_char(md.createtime,'yyyy-Q') as xx, count(md.billmaindataid) as 每天操作数量, sum(md.naturalamount)
from  tablename md
--where md.currentstate != 22
group by to_char(md.createtime,'yyyy-Q')
order by xx desc 


//按自然周统计 
select to_char(md.createtime,'yyyy-iw') as xx, count(md.billmaindataid) as 每天操作数量, sum(md.naturalamount)
from  tablename md
--where md.currentstate != 22
group by to_char(md.createtime,'yyyy-iw')
order by xx desc   
 
 

你可能感兴趣的:(oracle数据库)