当前位置:数据库 > 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

 


Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,