答案 0 :(得分:2)
您可以使用regexp_split_to_table来分割单词。假设您的表名是“product”而列是“name”,这里是sql:
SELECT regexp_split_to_table(name, E'\\s+') as name FROM product;
完整测试SQL结果如下:
create table product(
name varchar(200)
);
insert into product values('microsoft office');
insert into product values('virtual studio');
insert into product values('adobe reader');
insert into product values('adobe photoshop 9');
insert into product values('paint');
insert into product values('google chrome');
SELECT regexp_split_to_table(name, E'\\s+') as name FROM product;
结果:
name
1 microsoft
2 office
3 virtual
4 studio
5 adobe
6 reader
7 adobe
8 photoshop
9 9
10 paint
11 google
12 chrome
答案 1 :(得分:0)
您可以使用split_part
功能和union
来获得所需的结果,如下所示。
select * from (
SELECT split_part(c1, ' ', 1) as Name from t1
union all
SELECT split_part(c1, ' ', 2) from t1
) t
where t.Name <> ''
order by 1;
外部查询用于过滤掉是否存在任何空字符串输出,例如如果是paint
。
<强>结果:强>
name
----------
adobe
chrome
google
microsoft
office
paint
reader
studio
virtual
您可以查看演示 here