mysql - MySql 中的非法混合排序规则错误

标签 mysql collation mysql-error-1267

刚刚从上一个问题中得到了这个答案,它很有效!

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount 
FROM ratings WHERE month='Aug' GROUP BY username HAVING TheCount > 4
ORDER BY TheAverage DESC, TheCount DESC

但是当我把这个额外的位插入它时会出现这个错误:

Documentation #1267 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin1_general_ci,IMPLICIT) for operation '='

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount FROM 
ratings WHERE month='Aug' 
**AND username IN (SELECT username FROM users WHERE gender =1)**
GROUP BY username HAVING TheCount > 4 ORDER BY TheAverage DESC, TheCount DESC

表格是:

id、用户名、等级、月份

最佳答案

以下是检查哪些列是错误排序规则的方法:

SELECT table_schema, table_name, column_name, character_set_name, collation_name

FROM information_schema.columns

WHERE collation_name = 'latin1_general_ci'

ORDER BY table_schema, table_name,ordinal_position; 

这是修复它的查询:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET latin1 COLLATE 'latin1_swedish_ci';

Link

关于mysql - MySql 中的非法混合排序规则错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1241856/

相关文章:

MySQL 有效搜索多列(很多行)

php - SQL 查询 - INSERT 但仅当记录尚不存在时?

php - 将 MySQL 解析为 JSON 数组,并在 PHP 中进行数据操作

php - 如何在mysql数据库中存储和获取精确的字符?

Mysql转换表,排序规则不变

mysql - 在 MySQL 中加入查询

mysql - 如何使用 json 将元组数组传递给 sql 语句

mysql - django扩展查询条件 `COLLATION`

php - MYSQL查询两个不同字段的表