我想创建一个查询,它将输出所有可能的多个列。输入将如下所示。
Keyword 1|Keyword 2|Keyword 3
---------+---------+----------
shoes |buy
gloves |online
shirts |第二个假设输入如下所示
Keyword 1|Keyword 2|Keyword 3
---------+---------+----------
shoes |buy |shop
gloves |online
shirts |1日的结果如下:买鞋,买手套,买衬衫,在线买鞋,在线买手套,在线买衬衫
2号的结果如下:鞋子购买,手套购买,衬衫购买,鞋子在线,手套在线,衬衫在线,鞋子购买商店,手套购买商店,衬衫购买商店,鞋子在线商店,手套在线商店,衬衫在线商店
有没有一种方法可以写一个在两种情况下都能工作的查询?列数可能会更改为最多5列。
谢谢
发布于 2017-09-08 05:03:20
在同一个表之间执行笛卡尔连接:
select t1.col, t2.col, t3.col
from tab t1, tab t2, tab t3如果你想消除重复项,你可以尝试这个技巧:
select t1.col, t2.col, t3.col
from tab t1
join tab t2 on t1.col != t2.col
join tab t3 on t2.col != t3.col and t3.col != t1.col您可以在此处了解不同的选项:http://www.postgresqltutorial.com/postgresql-cross-join/
https://stackoverflow.com/questions/46105011
复制相似问题