oracle查询月区间,Oracle查询指定日期区间内不同工资水平区间员工的平均工资

具体一点,我有一个表sda,我想查询sda表内在13年1月到6月之间每个月工资高于5000的员工的平均工资,工资在3000到5000之间的员工的平均工资和工资在2000到3000之间的员工的平均工资。

我现在能写出来某个月里面的平均数据

select sum(case when(a.cpcavg>=5000) then a.cpcavg end) bb,

count(case when(a.cpcavg>=500) then a.cpcavg end)bb2,

sum(case when(a.cpcavg>=50 and a.cpcavg<500) then a.cpcavg end) cc,

count(case when(a.cpcavg>=50 and a.cpcavg<500) then a.cpcavg end) cc2 ,

sum(case when(a.cpcavg>=10 and a.cpcavg<50) then a.cpcavg end) dd,

count(case when(a.cpcavg>=10 and a.cpcavg<50) then a.cpcavg end) dd2,

sum(case when(a.cpcavg<10) then a.cpcavg end) ee,

count(case when(a.cpcavg<10) then a.cpcavg end) ee2,

from

(

select sda.accountid,

cast ( sum(sda.cpcconsume/100)/to_char(last_day(to_date('20130101','yyyy-mm-dd')),'dd') as number(12,2) ) cpcavg

from queryman.stat_day_account sda, queryman.account acc

where sda.cpcconsume>0 and sda.accountid=acc.i_account_id and acc. agent_type=1 and acc.classify in (1,2,3)

and sda.createdate>=to_date('20130101','yyyymmdd')

and sda.createdate

group by sda.accountid

) a

我现在可以计算出1月份每个区间员工的数据(符合条件的员工的平均工资之和和这些员工的个数)

我的问题是:

1.如何利用bb,bb2这些数计算出来平均数据

2.如何在一条sql语句中计算出来所有6个月的数据,而不是想现在这样把日期写死在语句中,每算一个月都要手动修改语句。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值