首页 > 解决方案 > sqlite 从具有多个“名称”的单列中选择 DISTINCT?

问题描述

我有一张有中文拼音的桌子。我想获得所有独特的音节发音。

我跑了

SELECT DISTINCT col FROM tab

但它给了我太多。

我的专栏有像

a1

a2

a3

a4

但它也有多个单词值,其中可能包含一个唯一值,例如:

a1 巴1

a2 fa1

我如何使用 distinct 自己也获得像“ba1”和“fa1”这样的值?

标签: sqlite

解决方案


您可以使用 UNION 也拒绝重复:

select col from tab where col not like '% %'
union
select substr(col, 1, instr(col, ' ') - 1) from tab where col like '% %'
union
select substr(col, instr(col, ' ') + 1) from tab where col like '% %'

查看演示


推荐阅读