请问 下面的表该如何排序?我有下面的表。次序如下 其中第5个记录和第6条记录次序颠倒了。这个表数据量比较大。 用什么方法可以对这个表中的 b列排序。使其能够按照升序排列。
a b
1 #1杆塔
2 #2杆塔
3 #3.1杆塔
4 #3.2杆塔
5 #5杆塔
6 #4杆塔
7 #6杆塔
8 #7杆塔
9 #9杆塔
10 #8杆塔现在要做的事情就是把 次序不对的列找出来。 不是排序。比如上列中b列第5,第6列。第9,10次序不对。 现在要把其中的列找出来。
5 #5杆塔
6 #4杆塔
9 #9杆塔
10 #8杆塔
就是把这样的列能够找出来。
a b
1 #1杆塔
2 #2杆塔
3 #3.1杆塔
4 #3.2杆塔
5 #5杆塔
6 #4杆塔
7 #6杆塔
8 #7杆塔
9 #9杆塔
10 #8杆塔现在要做的事情就是把 次序不对的列找出来。 不是排序。比如上列中b列第5,第6列。第9,10次序不对。 现在要把其中的列找出来。
5 #5杆塔
6 #4杆塔
9 #9杆塔
10 #8杆塔
就是把这样的列能够找出来。
解决方案 »
- Oracle数据库备份问题!
- oracle 包的问题
- oracle10g 表闪回,提示名称为ORA-01555:快照过旧:回退段号3("SYSSMU3$")过小
- 求查询某个字段不重复的sql语句
- 请问谁写过OCI的程序,哪里有OCI的资料下载?请帮助我!
- 如何恢复数据
- 急问高手:如何用c语言把自建的缓冲区中的数据写入oracle数据库?
- 诸位"DESC tablename"这句话能用"SELECT..."写出来吗?怎么写?请帮忙.谢谢.
- oracle的帮助系统做的不如sql server
- 问题大条了,数据库联机redo日志坏了,怎么搞?在线等待中.....
- pro*c 里怎么将select 的返回内容赋值给变量那?
- ORA-04091: 表 EGIS_ADMIN.RESOURCE_TYPE 发生了变化, 触发器/函数不能读它
as
(
select 1 b,'#1杆塔'a from dual
union all
select 2,'#2杆塔' from dual
union all
select 3,'#3.1杆塔' from dual
union all
select 4,'#3.2杆塔' from dual
union all
select 5,'#5杆塔' from dual
union all
select 6,'#4杆塔' from dual
union all
select 7,'#6杆塔' from dual
union all
select 8,'#7杆塔' from dual
)
select a,b
from
(select a,b,row_number() over(partition by 1 order by a) rn from temp order by a,b)
where b<>rn
--result:#4杆塔 6
#5杆塔 5
as
(
select 1 b,'#1杆塔'a from dual
union all
select 2,'#2杆塔' from dual
union all
select 3,'#3.1杆塔' from dual
union all
select 4,'#3.2杆塔' from dual
union all
select 5,'#5杆塔' from dual
union all
select 6,'#4杆塔' from dual
union all
select 7,'#6杆塔' from dual
union all
select 8,'#7杆塔' from dual
union all
select 9,'#9杆塔' from dual
union all
select 10,'#8杆塔' from dual
)
select a,b
from
(select a,b,row_number() over(partition by 1 order by a) rn from temp order by a,b)
where b<>rn
--result:#4杆塔 6
#5杆塔 5
#8杆塔 10
#9杆塔 9
2 select 1 a, '#1杆塔' b from dual union all
3 select 2 a, '#2杆塔' b from dual union all
4 select 3 a, '#3.1杆塔' b from dual union all
5 select 4 a, '#3.2杆塔' b from dual union all
6 select 5 a, '#5杆塔' b from dual union all
7 select 6 a, '#4杆塔' b from dual
8 ) select a, b from (select temp.*, row_number() over(order by a asc) a_ord,r
ow_number() over(order by to_number(substr(b, 2, length(b)-3)) asc) b_ord from t
emp) t where t.a_ord<>t.b_ord; A B
---------- --------
6 #4杆塔
5 #5杆塔
SQL> select * from t; A B
--------------------------------------- --------------------
1 #1¸ËËþ
2 #2¸ËËþ
3 #3.1¸ËËþ
4 #3.2¸ËËþ
5 #5¸ËËþ
6 #4¸ËËþ
7 #6¸ËËþ
8 #7¸ËËþ
9 #9¸ËËþ
10 #8¸ËËþ10 rows selectedSQL>
SQL> with tt as (
2 select a, b,c-lag(c,1,0)over(order by a) d,lag(c)over(order by a) e from (
3 select a,b,replace(replace(b,'#',''),'¸ËËþ','') c from t
4 )
5 )
6 select a,b from tt where tt.a in(
7 select a from tt where d<0
8 union
9 select cast(e as number) from tt where d<0
10 ); A B
--------------------------------------- --------------------
5 #5¸ËËþ
6 #4¸ËËþ
9 #9¸ËËþ
10 #8¸ËËþSQL>
SQL> select * from t; A B
--------------------------------------- --------------------
1 #1杆塔
2 #2杆塔
3 #3.1杆塔
4 #3.2杆塔
5 #5杆塔
6 #4杆塔
7 #6杆塔
8 #7杆塔
9 #9杆塔
10 #8杆塔10 rows selectedSQL>
SQL> with tt as (
2 select a, b,c-lag(c,1,0)over(order by a) d,lag(c)over(order by a) e from (
3 select a,b,replace(replace(b,'#',''),'杆塔','') c from t
4 )
5 )
6 select a,b from tt where tt.a in(
7 select a from tt where d<0
8 union
9 select cast(e as number) from tt where d<0
10 ); A B
--------------------------------------- --------------------
5 #5杆塔
6 #4杆塔
9 #9杆塔
10 #8杆塔SQL>
用楼上的再运行的时候报上面的错误。我的2个字段都是varchar2(50)的。
select 1 a, '#1杆塔' b from dual union all
select 2 a, '#2杆塔' b from dual union all
select 3 a, '#3.1杆塔' b from dual union all
select 4 a, '#3.2杆塔' b from dual union all
select 5 a, '#5杆塔' b from dual union all
select 6 a, '#4杆塔' b from dual
)
select a, b from (select temp.*, row_number() over(order by a asc) a_ord,
row_number() over(partition by 1 order by to_number(substr(b, 2, length(b)-3)) asc) b_ord from temp) t where t.a_ord <>t.b_ord;