我想根据某种字母顺序对MySQL查询进行排序。更准确地说,取决于网页,字母表的起始字母可以更改。
例如,我想根据这些订单通过查询进行订购:
[B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X, Y,Z,A] 要么 [H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A,B,C,D]
假设我的查询非常简单,如下所示:
SELECT name
FROM table
ORDER BY name ASC
是否只能使用MySQL做到这一点?
非常感谢。
答案 0 :(得分:2)
SELECT * FROM my_table;
+-----+---------------+
| id | element |
+-----+---------------+
| 88 | Actinium |
| 12 | Aluminium |
| 94 | Americium |
...
| 69 | Ytterbium |
| 38 | Yttrium |
| 29 | Zinc |
| 39 | Zirconium |
+-----+---------------+
SELECT * FROM my_table ORDER BY element <'M',element;
+-----+---------------+
| id | element |
+-----+---------------+
| 11 | Magnesium |
| 24 | Manganese |
| 108 | Meitnerium |
...
| 81 | Lead |
| 2 | Lithium |
| 115 | Livermorium |
| 70 | Lutetium |
+-----+---------------+