2012-07-31 56 views
5

做以下查詢:複雜MySQL的ORDER BY

SELECT title FROM table ORDER BY title 

給我:

"Hello" 
"Zebra" 
Apple 
Beta 
Cactus 

我怎麼會爲了通過第一字母字符,爲了得到:

Apple 
Beta 
Cactus 
"Hello" 
"Zebra" 

回答

6

在排序數據之前,您必須刪除引號。您可以使用TRIM功能輕鬆地刪除它們在MySQL爲:

SELECT title 
FROM table 
ORDER BY TRIM(BOTH '"' FROM title); 
3
...ORDER BY REPLACE(title, '"', ''); 
3
SELECT title FROM table ORDER BY TRIM(LEADING '"' FROM title)