我怎么能在mysql中自然排序?我跟着表:

时间:2014-06-13 06:46:41

标签: mysql sorting

我怎么能在mysql中自然排序?我跟着表:

CREATE TABLE sortnum
    (`name` varchar(255))
;

INSERT INTO sortnum
    (`name`)
VALUES
    ('atul'), 
    ('test-2~'), 
    ('Room 1'),  
    ('Room 11'),
    ('Room 2'),
    ('Room 3'),
    ('Room 4'),
    ('Room 1025'),
    ('Room 120'),
    ('Room 998'),
    ('test-1~!@#$%^&*()_+{}:"<>?/.,;][') 
;

如果有人能够提供实施所需的解决方案,那就太棒了。

1 个答案:

答案 0 :(得分:0)

你可以通过这种方式得到答案......享受

SELECT name, 
CONVERT(REPLACE(name, SUBSTRING_INDEX(name, REVERSE(CONVERT(REVERSE(name), SIGNED)), 1), ''),SIGNED) as t,
SUBSTRING_INDEX(name, REVERSE(CONVERT(REVERSE(name), SIGNED)), 1) AS d
FROM sortnum
ORDER BY d, t ASC;