oracle 分析函数dense_rank()

本文介绍如何使用SQL进行复杂的排名查询,包括如何获取特定条件下的峰值数据、如何查询成绩排名第三的学生信息等。通过具体实例展示了dense_rank()和row_number()等窗口函数的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--本网发送秒峰值
SELECT *
  FROM (SELECT  monthday,
               tc,
               ct,
               dense_rank() over(PARTITION BY monthday ORDER BY ct DESC) orderid
          FROM (SELECT t.monthday,
                       to_char(t.insertime, 'yyyy-mm-dd hh24:mi:ss') tc,
                       COUNT(1) ct
                  FROM t_dz_msa_mediasend_his t
                 WHERE t.monthday LIKE  '11__'
                           AND
                 t.sendtime > trunc(SYSDATE, 'yy')
                 AND t.sendno  LIKE '010%'
                 GROUP BY  t.monthday,
                          to_char(t.insertime, 'yyyy-mm-dd hh24:mi:ss')
                 ORDER BY ct DESC))
           WHERE ORDERid <=1

 

按业务按日期,分钟峰值
SELECT *
  FROM (SELECT  monthday,
                serviceid,
               tc,
               ct,
               dense_rank() over(PARTITION BY monthday,serviceid ORDER BY ct DESC) orderid
          FROM (SELECT t.monthday,t.serviceid,
                       to_char(t.insertime, 'yyyy-mm-dd hh24:mi') tc,
                       COUNT(1) ct
                  FROM t_dz_msa_mediasend_his t
                 WHERE t.monthday = '0109'
                           AND
                 t.sendtime > trunc(SYSDATE, 'yy')
                 GROUP BY  t.monthday,t.serviceid,
                          to_char(t.insertime, 'yyyy-mm-dd hh24:mi')
                 ORDER BY ct DESC))
           WHERE ORDERid <=1
          
  查询出学生中成绩第三的所有人信息        
  select *
  from t_student a
 where exists (select id from (select id, dense_rank() over(order by sum(score) desc) rnum
                  from t_student t
                 group by id)
             where rnum = 3
           and a.id = id)
          
          
 select *
  from t_student
 where score = (select score
                  from (select tt.*, rownum rn
                          from (select distinct (t.score)
                                  from t_student t
                                 order by to_number(t.score) desc) tt)
                 where rn = 3)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值