我有一张这样的表:
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 ...你能在你的环境中测试查询吗?
提前谢谢!
答案 0 :(得分: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