当前位置:数据库 > Oracle >>

oracle分组排序取第一条数据

oracle分组排序取第一条数据
 
/* 分组排序取第一条数据*/
SELECT *
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY taskbreakid ORDER BY responsedate DESC) LEV,   r.*
        --  select r.*     
          FROM tablename r 
 WHERE LEV = 1


 /*
 --ORDER BY responsedate DESC
 taskbreakid  ---> 分组列
 responsedate ---> 分组中排序列
 tablename    ---> 表名
 */

/*   取第一条数据 */
select * from (    select * from tablename t order by paisulie    )   where rownum = 1

 


CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,