--
1-1-1 排序
1 |
ORDER BY CHAR_LENGTH(question_code) DESC, question_code DESC; |
--
使用中文筆劃順序
1 |
CONVERT(name using big5) |
--
數字 + 中文的排序
- MySQL: order a string column as an integer
- MySQL order by convert varchar as unsigned and sort "0" to the last
1 |
ORDER BY CAST(name AS UNSIGNED) DESC |
--
自定義排序順序
1 |
ORDER BY FIELD(Language,'ENU','JPN','DAN'), ID |
--
根據 LIKE 自定義順序
1 2 3 4 5 |
ORDER BY CASE WHEN name LIKE "%John%" THEN 1 WHEN name LIKE "%Doe%" THEN 2 ELSE 3 END |
--
根據某段內容排序
- How to order by certain part of a string in MySQL? (tutorialspoint.com)
- MySQL :: MySQL 8.0 Reference Manual :: 12.8 String Functions and Operators
1 2 3 |
ORDER BY SUBSTRING(exam_source, 5, 3) DESC, SUBSTRING(exam_source, 9, 1) DESC; |
字串的擷取有多個 function 請根據需求取用
--
2,455 total views, 1 views today