加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle 按照分组字段,排序字段取出第一行

发布时间:2020-12-12 18:49:22 所属栏目:百科 来源:网络整理
导读:wm_concat在行转列的时候非常有用,但在行转列的过程中的排序问题常常难以控制。 可见下面例子: 准备测试表: drop table t; create table t (n number,m number); insert into t values(1,1); insert into t values(5,3); insert into t values(3,3); inse

wm_concat在行转列的时候非常有用,但在行转列的过程中的排序问题常常难以控制。

可见下面例子:
准备测试表:
drop table t;
create table t (n number,m number);
insert into t values(1,1);
insert into t values(5,3);
insert into t values(3,3);
insert into t values(6,5);
insert into t values(7,2);
insert into t values(2,2);
insert into t values(0,1);
insert into t values(11,1);
insert into t values(15,3);
insert into t values(13,3);
insert into t values(16,5);
insert into t values(17,2);
insert into t values(12,2);
insert into t values(10,1);
commit;

SQL> select * from t order by 2,1;

N M
———- ———-
0 1
1 1
10 1
11 1
2 2
7 2
12 2
17 2
3 3
5 3
13 3
15 3
6 5
16 5
--按照m分组字段,n排序字段取出第一行

select * from ( select m,row_number() over (partition by m order by n) rn from t ) where rn<=1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读