Mariadb:Group by失败,在varchar(255)COLLATE utf8mb4\u unicode\u ci列中有符号

Mariadb:Group by失败,在varchar(255)COLLATE utf8mb4\u unicode\u ci列中有符号,mariadb,Mariadb,我的桌子上有这样的表情符号: MariaDB> SELECT HEX(value), value FROM `emojis`; +----------------------------+-------+ | HEX(value) | value | +----------------------------+-------+ | F09F9AA9 | HEX is not an aggregate function, s

我的桌子上有这样的表情符号:

MariaDB> SELECT HEX(value), value FROM `emojis`;
+----------------------------+-------+
| HEX(value)                 | value |
+----------------------------+-------+
| F09F9AA9                   | 
HEX
is not an aggregate function, so you cannot use as one with
GROUP BY
. If you wish to get the different emojis and the respective hex-values use
DISTINCT
.

You should (see Character Collating Weights) store the emojis as
utf8mb4_bin
instead
utf8mb4_unicode_ci
. The reason for this is how the character's collating weight is determined. See handling of comparision of characters with WEIGTH_STRING-function.

SELECT DISTINCT value, HEX(value) 
FROM emojis;
MariaDB>选择十六进制(值),从'emojis'中选择值;
+----------------------------+-------+
|十六进制(值)|值|
+----------------------------+-------+

|F09F9AA9 |
HEX
不是聚合函数,因此不能与
GROUP BY
一起使用。如果希望获得不同的表情和相应的十六进制值,请使用
DISTINCT

您(请参见字符排序权重)将表情存储为
utf8mb4\u-bin
而不是
utf8mb4\u-unicode\u-ci
。原因是字符的排序权重是如何确定的。请参阅使用-函数处理字符比较

SELECT value
FROM emojis
GROUP BY value;

这样的查询不应使用:

SELECT id, value
FROM `emojis`
GROUP BY value COLLATE utf8mb4_bin;

只有在将普通列与聚合函数混合使用时,才应使用分组依据。如前所述,改用
DISTINCT

多亏了你的回答,我明白了在使用
DISTINCT
groupby
和其他比较字符串的函数时,使用
utf8mb4\u-bin
utf8mb4\u-unicode\u-ci
会有什么不同

但在我的例子中,我无法更改列的编码,但我了解到可以在请求中指定排序规则,如下所示:

MariaDB> SELECT HEX(value), value FROM `emojis`;
+----------------------------+-------+
| HEX(value)                 | value |
+----------------------------+-------+
| F09F9AA9                   | 
HEX
is not an aggregate function, so you cannot use as one with
GROUP BY
. If you wish to get the different emojis and the respective hex-values use
DISTINCT
.

You should (see Character Collating Weights) store the emojis as
utf8mb4_bin
instead
utf8mb4_unicode_ci
. The reason for this is how the character's collating weight is determined. See handling of comparision of characters with WEIGTH_STRING-function.

SELECT DISTINCT value, HEX(value) 
FROM emojis;

警告:如果
sql\u模式
ONLY\u FULL\u GROUP\u BY

在Unicode历史上的某个点上,表情符号的排序规则发生了更改,则此功能不起作用。旧的排序规则utf8mb4\u unicode\u ci
(版本4.0)将它们视为相等。较新的排序规则utf8mb4\U unicode\U 520(版本5.20)将它们视为不相等


分组依据
订单依据
感谢您的帮助,我更新了添加失败查询的功能,例如:。但是引擎看不到两个表情符号不一样,这不是很奇怪吗?