oralce汇总函数备忘

select nvl(schememoncode,'小计'),sum(providesum),rank() over (order by sum(providesum) desc) fare_rank
from providescheme
group by schememoncode


select decode(grouping(schememoncode),1,'标准小计',to_char(schememoncode)) schememoncode,decode(grouping(providelevel),1,'月小计',to_char(providelevel)) providelevel,
sum(providesum),rank() over (partition by schememoncode order by sum(providesum) asc) area_rank
from providescheme
group by cube(schememoncode,providelevel)


select schememoncode,providelevel,curprovidesum,
lag(curprovidesum,2,0) over (partition by schememoncode order by providelevel) pre2_curprovidesum,
lag(curprovidesum,1,0) over (partition by schememoncode order by providelevel) pre1_curprovidesum,
lead(curprovidesum,1,0) over (partition by schememoncode order by providelevel) nex1_curprovidesum,
lead(curprovidesum,2,0) over (partition by schememoncode order by providelevel) nex2_curprovidesum
from
(
select decode(grouping(schememoncode),1,'标准小计',to_char(schememoncode)) schememoncode,decode(grouping(providelevel),1,'月小计',to_char(providelevel)) providelevel,
sum(providesum) curprovidesum
from providescheme
group by schememoncode,providelevel
)

 

select schememoncode,providelevel,curprovidesum,
    sum(curprovidesum)
             over (  partition by providelevel
                     order by to_number(schememoncode)
                    range between 1 preceding and 1 following ) "3month_sum",
     avg(curprovidesum)
             over (  partition by providelevel
                     order by to_number(schememoncode)
                    range between 1 preceding and 1 following ) "3month_avg",
    max(curprovidesum)
             over (  partition by providelevel
                     order by to_number(schememoncode)
                     range between 1 preceding and 1 following ) "3month_max",
     min(curprovidesum)
             over (  partition by providelevel
                     order by to_number(schememoncode)
                     range between 1 preceding and 1 following ) "3month_min"
from
(
select decode(grouping(schememoncode),1,'标准小计',to_char(schememoncode)) schememoncode,decode(grouping(providelevel),1,'月小计',to_char(providelevel)) providelevel,
sum(providesum) curprovidesum
from providescheme
group by schememoncode,providelevel
)


select decode(grouping(schememoncode),1,'标准小计',to_char(schememoncode)) schememoncode,decode(grouping(providelevel),1,'月小计',to_char(providelevel)) providelevel,
sum(providesum) curprovidesum,
ratio_to_report(sum(providesum)) over  ( partition by schememoncode ) area_pct
from providescheme
group by schememoncode,providelevel
  compute sum of curprovidesum on schememoncode
  compute sum of area_pct on schememoncode
 

 select bill_month,area_code,sum(local_fare) local_fare,
    ratio_to_report(sum(local_fare)) over
       ( partition by bill_month ) area_pct
  from t
 group by bill_month,area_code
  break on bill_month skip 1
  compute sum of local_fare on bill_month
  compute sum of area_pct on bill_month


create table demo2 as
select object_id,owner... from
(select demo.*,row_number() over(partition by object_id order by rowid) rn from demo)
where rn = 1;
truncate table demo; insert into demo select * from demo2; drop table demo2;

 

 

 

 

 

 

 


select decode(grouping(schememoncode),1,'标准小计',to_char(schememoncode)) schememoncode,decode(grouping(providelevel),1,'月小计',to_char(providelevel)) providelevel,sum(providesum)
from providescheme
group by cube(schememoncode,providelevel)


decode(grouping(providelevel),1,'标准小计',to_char(providelevel)) providelevel,

select * from (
select memberid,providedmoney,dense_rank() over (order by providedmoney desc) add_rank
from providepool
) a where  a.add_rank<10

select idcard from member group by idcard having count(id)>1
  select rowid row_id,row_number() over (partition by obj# order by rowid ) rn

select obj#,name from sys.obj$ where name='IDCARD'

 select row_id from (
      select rowid row_id,row_number() over (partition by idcard order by rowid ) rn from member
   ) where rn <> 1 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值