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 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|