0

我有一张这样的桌子:

id | name 
----------------
 1 | àbbot
 2 | about
 3 | zorro

我想在不区分大小写的上下文中选择第一个字母,如下所示:

let
----------
a
z

但是其中任何一个,使用任何 unicode 排序规则,都会给出相同的错误结果:

SELECT LOWER(SUBSTR(name,1,1)) AS let FROM t GROUP BY let

SELECT LOWER(SUBSTR(name,1,1)) AS let FROM t GROUP BY letter ORDER BY let ASC

SELECT * FROM
     (SELECT LOWER(SUBSTR(name,1,1)) AS let FROM t ORDER BY let DESC) AS x
GROUP BY let ORDER BY let ASC

错误的结果:

let
----------
à
z

有没有办法在不强制转换的情况下修复排序?(因为我也必须涵盖非拉丁语言,例如日语)。

也许我有一个旧版本的 MySQL……你能在你的环境中测试查询吗?

先感谢您!

4

1 回答 1

0

没关系,找到解决方案

SELECT UPPER(SUBSTR(name,1,1)) AS let FROM 
    (SELECT name FROM t ORDER BY name DESC) AS x
GROUP BY let ORDER BY let ASC
于 2012-11-15T13:14:44.560 回答