-2

表中的列:interval varchar(12)

当用户像这样在此列中输入数据时:

1
10-20
3-5
5-3
25-34
20-25
2
4-8

和输出应该是这样的:

1
2
3-5
4-8
9-10
10-20
20-25
25-34
4

1 回答 1

2
SELECT  col
FROM
(
        SELECT '1' col  FROM DUAL UNION ALL
        SELECT '10-20'  FROM DUAL UNION ALL
        SELECT '3-5'    FROM DUAL UNION ALL
        SELECT '5-3'    FROM DUAL UNION ALL
        SELECT '25-34'  FROM DUAL UNION ALL
        SELECT '20-25'  FROM DUAL UNION ALL
        SELECT '2'      FROM DUAL UNION ALL
        SELECT '4-8'    FROM DUAL
)
ORDER   BY
        TO_NUMBER(regexp_substr(col, '\w+', 1, 1))
,       TO_NUMBER(regexp_substr(col, '\w+', 1, 2))


1
2
3-5
4-8
5-3
10-20
20-25
25-34
于 2013-09-23T11:32:12.053 回答