Postgres查询以创建组合 [英] Postgres query to create combinations
本文介绍了Postgres查询以创建组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的表-
tableCountry
- 美国
- 英国
- 德国
我想写一个查询列出以下组合-
I want to write a query to list out the following combinations -
>USA-UK
>USA-Germany
>UK-USA
>UK-Germany
>Germany-USA
>Germany-UK
这样的组合列表是否可以通过postgresql来实现?
Is such a combination listing possible through postgresql?
谢谢。
推荐答案
这很简单:
SELECT t1.Country || '-' || t2.Country
FROM table t1
JOIN table t2 ON t1.Country <> t2.Country;
这篇关于Postgres查询以创建组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文