• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Myth's space
好好学习,不见进步
博客园    首页    新随笔    联系   管理    订阅  订阅

ORACLE Keep dense_rank

The DENSE_RANK function works return sequence value for the order seqence.

example:

SQL> with t as (
  
2  select 1 mon, 'Jon' name,24 age, 100000 money from dual union all
  
3  select 1, 'Kim',24, 3230000 from dual union all
  
4  select 1, 'Jissca',25, 235556565 from dual
  
5  )
  
6  select mon,name,age,money,dense_rank() over (partition by mon order by money) rank from t;
 
       MON NAME          AGE      
MONEY       RANK
---------- ------ ---------- ---------- ----------
         1 Jon            24     100000          1
         
1 Kim            24    3230000          2
         
1 Jissca         25  235556565          3
 
SQL
>

 The FIRST or LASTfunction can used to return the first or last value for order sequence,

Say we want  to display the min value of money,age,along with the lowest and highest within their monwe may use something like:

 

SQL> with t as (
  
2  select 1 mon, 'Jon' name,24 age, 100000 money from dual union all
  
3  select 1, 'Kim',24, 3230000 from dual union all
  
4  select 1, 'Jissca',25, 235556565 from dual
  
5  )
  
6  select mon,min(age) keep (dense_rank first order by money)  age, min(money) money
  
7    from t
  
8  group by mon;
 
       MON        AGE      
MONEY
---------- ---------- ----------
         1         24     100000
 
SQL
>
posted @ 2009-11-16 11:03  Mr.Myth  阅读(791)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3