Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Postgres查询以创建组合_Sql_Postgresql - Fatal编程技术网

Sql Postgres查询以创建组合

Sql Postgres查询以创建组合,sql,postgresql,Sql,Postgresql,我有一张这样的桌子- 表格国家/地区 美国 英国 德国 我想写一个查询,列出以下组合- >USA-UK >USA-Germany >UK-USA >UK-Germany >Germany-USA >Germany-UK 这样的组合列表是否可以通过postgresql实现 谢谢。这很简单: SELECT t1.Country || '-' || t2.Country FROM table t1 JOIN table t2 ON t1.Country &

我有一张这样的桌子-

表格国家/地区

  • 美国
  • 英国
  • 德国
  • 我想写一个查询,列出以下组合-

    >USA-UK
    >USA-Germany
    >UK-USA
    >UK-Germany
    >Germany-USA
    >Germany-UK
    
    这样的组合列表是否可以通过postgresql实现

    谢谢。

    这很简单:

    SELECT t1.Country || '-' || t2.Country
      FROM table t1
      JOIN table t2 ON t1.Country <> t2.Country;
    
    选择t1.Country | |'-'| | t2.Country
    来自表t1
    将表t2连接到t1.Country t2.Country上;
    
    读者还想了解这一部分的后续内容。