3

这个查询:

SELECT customer_id, customer_name FROM customers WHERE isActive = '1' ORDER BY customer_name ASC

输出:

+-------------+-----------------------+
| customer_id | customer_name         |
+-------------+-----------------------+
|           1 | Äname                 |
|           2 | Aname                 |
|           3 | Bname                 |
+-------------+-----------------------+

为什么即使我有排序规则,它也不对特殊的瑞典字符进行排序utf8_swedish_ci

SHOW TABLE STATUS FROM myDatabase WHERE name = 'customers';

+-------------+----------------------------+
| Name        | Engine   | Collation       |
+-------------+----------------------------+
| customers   | MyISAM   | utf8_swedish_ci |
+-------------+----------------------------+

我什至尝试将排序规则放在我的查询中:

SELECT * FROM customers WHERE isActive = 1 COLLATE utf8_swedish_ci ORDER BY customer_name ASC

但后来我得到:

Error Code: 1253. COLLATION 'utf8_swedish_ci' is not valid for CHARACTER SET 'binary'
4

1 回答 1

4

不知道默认行为,但正确的语法是:

SELECT customer_id, customer_name
FROM customers
WHERE isActive = '1'
ORDER BY customer_name COLLATE utf8_swedish_ci ASC
于 2012-12-04T15:28:59.917 回答