您可以在SQL中执行此操作,尽管它不是很漂亮。
select distinct reverse(substring_index(reverse(substring_index(tags, ',', n.n)), ',', 1)) as wordfrom t cross join (select 1 as n union all select 2 as n union all select 3 as n union all select 4 as n) nhaving word is not null
您需要确保子查询的
n每个标签中至少包含单词数。
这是演示此的SQLFiddle。
这是将原始数据与序列号交叉连接。然后,使用从标签字符串中选择第n个值
substring_index()。
要获得最大数量的标签,您可以执行以下操作:
select max(length(tags) - length(replace(tags, ',', 1))+1from t



