gpt4 book ai didi

mysql选择不同的字母,包括扩展的拉丁字符

转载 作者:可可西里 更新时间:2023-11-01 08:16:42 26 4
gpt4 key购买 nike

原始问题:

Table structure:

CREATE TABLE `texts` (
`letter` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`text` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
INDEX (`letter` ASC),
INDEX (`text` ASC)
)
ENGINE InnoDB
CHARACTER SET utf8
COLLATE utf8_general_ci;

Sample data:

INSERT INTO `texts`
(`letter`, `text`)
VALUES
('a', 'Apple'),
('ā', 'Ābols'),
('b', 'Bull'),
('c', 'Cell'),
('č', 'Čakste');

The query which I'm executing:

SELECT DISTINCT `letter` FROM `texts`;

Expected results:

`letter`
a
ā
b
c
č

Actual results:

`letter`
a
b
c

I've tried many utf8 collations (utf8_[bin|general_ci|unicode_ci], utf8mb4_[bin|general_ci|unicode_ci] etc), none of them work. How to fix this?

Edit for clarification: what I want is not just to get all the letters out, but also get them in the order I specified in the expected results. utf8_bin gets all the letters, but they are ordered in the wrong way - extended latin characters follow only after all the basic latin characters (example: a, b, c, ā, č). Also, the actual table I'm using has many texts per letter, so grouping is a must.

编辑 #2:这是来自实时站点的完整表格数据 - http://pastebin.com/cH2DUzf3执行该 SQL 并在之后运行以下查询:

SELECT DISTINCT BINARY `letter` FROM `texts` ORDER BY `letter` ASC

产生几乎完美的结果,有一个异常(exception):字母“ū”“u”之前,至少可以说这很奇怪,因为所有其他扩展拉丁语字母出现在他们的基本拉丁版本之后。我该如何解决最后一个问题?

最佳答案

检查 Manual对于 BINARY 类型

SELECT DISTINCT BINARY `letter` FROM `texts` 

检查 SQL Fiddle

关于mysql选择不同的字母,包括扩展的拉丁字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24466208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com