Illegal mix of collations error in MySql

后端 未结 19 2230
醉梦人生
醉梦人生 2020-11-29 01:11

Just got this answer from a previous question and it works a treat!

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount 
FROM ratings         


        
19条回答
  •  粉色の甜心
    2020-11-29 02:07

    [MySQL]

    In these (very rare) cases:

    • two tables that really need different collation types
    • values not coming from a table, but from an explicit enumeration, for instance:

      SELECT 1 AS numbers UNION ALL SELECT 2 UNION ALL SELECT 3

    you can compare the values between the different tables by using CAST or CONVERT:

    CAST('my text' AS CHAR CHARACTER SET utf8)
    
    CONVERT('my text' USING utf8)
    

    See CONVERT and CAST documentation on MySQL website.

提交回复
热议问题