mysql查询中的非法混合排序错误

San*_*Rao 4 mysql sql collation

有没有办法比较mysql查询中生成的范围列?

SELECT ue.bundle,ue.timestamp,b.id,bv.id as bundleVersionId,bv.start_date,bv.end_date, bv.type,ue.type from (
 SELECT bundle,timestamp,tenant, case when Document_Id ='' then 'potrait'
 WHEN Document_Id<>'' then 'persisted' end   as type from uds_expanded ) ue
 JOIN bundle b on b.name=ue.bundle  join bundle_version bv on b.id=bv.bundle_id 
 WHERE ue.tenant='02306' and ue.timestamp >= bv.start_date and ue.timestamp <=bv.end_date and **ue.type=bv.type ;**
Run Code Online (Sandbox Code Playgroud)

当我尝试比较类型时,我收到以下错误

 Error Code: 1267. Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation '=' 0.000 sec
Run Code Online (Sandbox Code Playgroud)

kba*_*kba 6

坚持整个系统的一个编码/整理.现在你似乎在一个地方使用UTF8而在另一个地方使用latin1.转换后者也使用UTF8,你会很好.

您可以使用更改排序规则为UTF8

alter table <some_table> convert to character set utf8 collate utf8_general_ci;
Run Code Online (Sandbox Code Playgroud)


Tek*_*ekz 5

我认为有时问题是我们使用不同的 orm 实用程序来生成表,然后我们想通过 mysql 命令行或 MySql 工作台测试查询,然后这个问题是由于表整理和我们使用的命令行或应用程序的差异造成的。简单的方法是定义您的变量(用于针对表列测试查询的变量)

前任:

MySQL>
MySQL> set @testCode = 'test2' collate utf8_unicode_ci;
Query OK, 0 rows affected (0.00 sec)

MySQL> select * from test where code = @testCode;
Run Code Online (Sandbox Code Playgroud)

全部细节