做以下查詢:複雜MySQL的ORDER BY
SELECT title FROM table ORDER BY title
給我:
"Hello"
"Zebra"
Apple
Beta
Cactus
我怎麼會爲了通過第一字母字符,爲了得到:
Apple
Beta
Cactus
"Hello"
"Zebra"
?
做以下查詢:複雜MySQL的ORDER BY
SELECT title FROM table ORDER BY title
給我:
"Hello"
"Zebra"
Apple
Beta
Cactus
我怎麼會爲了通過第一字母字符,爲了得到:
Apple
Beta
Cactus
"Hello"
"Zebra"
?
在排序數據之前,您必須刪除引號。您可以使用TRIM
功能輕鬆地刪除它們在MySQL爲:
SELECT title
FROM table
ORDER BY TRIM(BOTH '"' FROM title);
...ORDER BY REPLACE(title, '"', '');
SELECT title FROM table ORDER BY TRIM(LEADING '"' FROM title)