我收到了以下查询和错误消息:
WITH full_table AS (
SELECT TRANSACTION_ID AS Transaction,USER_ID AS USER, TRANSACTION_TIMESTAMP AS TIMESTAMP, ORDER_LINE_ITEM, TIME_TAKEN, QUANTITY, TIME_STANDARD, transactions_department.DEPARTMENT, (TIME_STANDARD*QUANTITY) AS NORMALIZED_TIME_STANDARD
FROM pivoted_standards
INNER JOIN
transactions_department
ON
pivoted_standards.DEPARTMENT = transactions_department.DEPARTMENT
ORDER BY
USER, TIMESTAMP, ORDER_LINE_ITEM
) SELECT * FROM full_table
错误:
Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='
这个错误是关于我连接pivoted_standards. DEPARTMENT = transactions_department.DEPARTMENT的位置。这两个变量有相同的排序规则,但是一个是VARCHAR,另一个是文本。我如何将它们连接在一起?在这个查询中是否可以这样做?
1条答案
按热度按时间cqoc49vn1#
您应该能够通过在
transactions_department.DEPARTMENT
上添加COLLATE utf8mb4_general_ci
来解决此问题,如下所示:Here's a fiddle example
然而,这不是一个推荐的长期解决方案。我知道人们需要不同的排序规则是有原因的,所以考虑使用类似于
dept_id
和INT
的数据类型,并使用不同的排序规则来连接表。Example fiddle using INT datatype for join