日期:2014-05-16  浏览次数:21008 次

求排序
由如下数据
1
+1
2
2+
3
4
+5
5
5+

希望排序成
1
2
3
4
5
2+
5+
+1
+5


在线等!急。谢谢

------解决方案--------------------
SQL code

with t as (
select '1' b from dual 
union all
select '+2' b from dual 
union all
select '+1' b from dual 
union all
select '2' b from dual 
union all
select '1+' b from dual 
)

select t.b from t order by decode(instr(t.b,'+'),0,1,1,3,2),replace(t.b,'+','')

------解决方案--------------------
临时拼凑出来的,你可以先将就下,哈哈

WITH tt AS(
SELECT '1' AS A FROM DUAL
UNION ALL
SELECT '+1' FROM DUAL
UNION ALL
SELECT '2' FROM DUAL
UNION ALL
SELECT '2+' FROM DUAL
UNION ALL
SELECT '3' FROM DUAL
UNION ALL
SELECT '4' FROM DUAL
UNION ALL
SELECT '+5' FROM DUAL
UNION ALL
SELECT '5' FROM DUAL
UNION ALL
SELECT '5+' FROM DUAL
)
SELECT * FROM (SELECT * FROM tt WHERE LENGTH(A) = 1
ORDER BY A ASC) K
UNION ALL
SELECT * FROM (SELECT * FROM tt WHERE LENGTH(A) = 2 AND A NOT LIKE '+%'
ORDER BY A ASC)M
UNION ALL
SELECT * FROM (SELECT * FROM tt WHERE LENGTH(A) = 2 AND A LIKE '+%'
ORDER BY A ASC)L

------解决方案--------------------

探讨
SQL code


with t as (
select '1' b from dual
union all
select '+2' b from dual
union all
select '+1' b from dual
union all
select '2' b from dual
union all
select '1+' b from dual
)……

------解决方案--------------------
探讨
SQL code

with t as (
select '1' b from dual
union all
select '+2' b from dual
union all
select '+1' b from dual
union all
select '2' b from dual
union all
select '1+' b from dual
)
……

------解决方案--------------------
WITH T AS(
SELECT '1' AS A FROM DUAL
UNION ALL
SELECT '+1' FROM DUAL
UNION ALL
SELECT '2' FROM DUAL
UNION ALL
SELECT '2+' FROM DUAL
UNION ALL
SELECT '3' FROM DUAL
UNION ALL
SELECT '4' FROM DUAL
UNION ALL
SELECT '+5' FROM DUAL
UNION ALL
SELECT '5' FROM DUAL
UNION ALL
SELECT '5+' FROM DUAL
)
SELECT a from T ORDER BY length(a) ,REPLACE(a,'+','@')