MySQL 不会按瑞典字符排序 åäö 即使排序正确也无法正常工作

标签 mysql collation

这个查询:

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'

最佳答案

不知道默认行为,但是 the correct syntax是:

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

关于MySQL 不会按瑞典字符排序 åäö 即使排序正确也无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13706099/

相关文章:

php - 将 PHPMYADMIN 与谷歌云 SQL 结合使用

mysql - 如何计算该付款的到期金额?

python - 使用 SQL 索引时 SQLAlchemy 自定义排序算法

mysql - 更改所有现有的列排序规则

php - 通过 mysql 进行 JSON Android 登录验证

php - PHP和MySQL:mysqli_num_rows()期望参数1为mysqli_result,给定 bool 值

mysql - 如何与 Magento Commerce 进行数据库访问 (I/O)?

php - 如何: Match string from search box and proper case table data

mysql - 来自 C 应用程序和 mysql 控制台的不同 mysql 触发器

Mysql转换表,排序规则不变