我有一张这样的表:
NAME
-----
ABCD
PQRST
QWERTYU
XGGABC
我需要在第一个上显示最短的名字。我想知道如何排序这些如下
NAME
-----
ABCD
PQRST
XGGABC
QWERTYU
答案 0 :(得分:3)
使用:
order by len(name), name;
答案 1 :(得分:1)
SELECT * FROM (
SELECT 'XGGABC' as NAME
UNION
SELECT 'ABCD' AS NAME
UNION
SELECT 'PQRST' AS NAME
UNION
SELECT 'QWERTYU' AS NAME
)tmp ORDER BY len(NAME),NAME