Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
在postgresql中查找次关键字的重复项_Postgresql_Count_Duplicates_Temp Tables - Fatal编程技术网

在postgresql中查找次关键字的重复项

在postgresql中查找次关键字的重复项,postgresql,count,duplicates,temp-tables,Postgresql,Count,Duplicates,Temp Tables,我对Postgresql还相当陌生 我试图在显示整个表的同时找到备用键的重复数 我的表1如下所示 |studentid|name|major|countryid| |:-------:|:--:|:----:|:-------------:| |001|John|finance|1A| |002|Luc|Marketing|1B| |003|Thomas|Sales|1A| 我的2号桌是 |countryid|country| |:-------:|:-----:| |1A|Australia

我对Postgresql还相当陌生

我试图在显示整个表的同时找到备用键的重复数

我的表1如下所示

|studentid|name|major|countryid|
|:-------:|:--:|:----:|:-------------:|
|001|John|finance|1A|
|002|Luc|Marketing|1B|
|003|Thomas|Sales|1A|
我的2号桌是

|countryid|country|
|:-------:|:-----:|
|1A|Australia|
|1B|Spain|
所以每个表当然有很多行

我想要的结果是

|studentid|name|major|country|numberofstudentsfromthiscountry|
|:-------:|:--:|:---:|:-----:|:-----------------------------:|
|001|John|finance|Australia|2|
|002|Luc|Marketing|Spain|1|
|003|Thomas|Sales|Australia|2|

有人能帮我吗?

欢迎来到SO。你能解释一下你期望得到什么样的输出以及到目前为止你都做了些什么吗?这些表是如何关联的,它们之间似乎没有通过某个列的关系。哦,学生表有国家id的外键。这是这些表在国家id上的简单连接。如果没有匹配项,你只需要决定怎么做。内部联接将完全跳过它们,而外部联接将保留其中一个。看见看看备用语法,因为Postgres在这方面非常差,使用了自1992年以来就过时的语法。谷歌“ANSI/ISO连接语法”