Natural Order
Natural Order
- it is also called version sorting
intro
- 通常將字母和數字方開來處理,而數字的部分會以數字組的方式處理
- 以避免下列狀況
1
2
3
4
5
6
7// 按字母顺序排序:
1. 1111
2. 22
// 自然排序:
1. 22
2. 1111code example
1
2
3
4
5
6SELECT
CONCAT(prefix, suffix)
FROM
items
ORDER BY
prefix , suffix;1
2
3
4
5SELECT
item_no
FROM
items
ORDER BY CAST(item_no AS UNSIGNED) , item_no;1
2
3
4
5SELECT
item_no
FROM
items
ORDER BY LENGTH(item_no) , item_no;
reference
- SQLite Order By - Sorting Result Set in Various Orders
- SQLite Forum: Natural sort order
- MySQL Natural Sorting with ORDER BY clause
- Natural sorting of alphanumeric values in sqlite using android - Stack Overflow
- 自然排序顺序-维基百科
- sorting - SQLite 3 Version Sort String - Stack Overflow
- 自然排序
- Sorting for Humans : Natural Sort Order
- Windows Confidential: The Evolution of Sorting | Microsoft Docs
- sql - Natural Sort in MySQL - Stack Overflow