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 不带联接的两个不同表中的数组\u agg_Sql_Postgresql - Fatal编程技术网

Sql 不带联接的两个不同表中的数组\u agg

Sql 不带联接的两个不同表中的数组\u agg,sql,postgresql,Sql,Postgresql,我需要从两个不相关的不同表中获取作为数组的输入 样本数据 城市1表 名称 托普 城市1 10 城市2 20 你把事情复杂化了。只需使用两个标量子查询: select (select array_agg(tot_pop) from city1) as city_pop, (select array_agg(quota) from facilities) as facility_quot; 或者稍微快一点: select (array(select tot_pop from city

我需要从两个不相关的不同表中获取作为数组的输入

样本数据 城市1表

名称 托普 城市1 10 城市2 20
你把事情复杂化了。只需使用两个标量子查询:

select (select array_agg(tot_pop) from city1) as city_pop,
       (select array_agg(quota) from facilities) as facility_quot;
或者稍微快一点:

select (array(select tot_pop from city1)) as city_pop,
       (array(select quota from facilities)) as facility_quot;

请提供样品数据以及期望的结果。谢谢返回。我实际使用几何图形,并使用st_accum在postgis中聚合几何图形列。但这个例子应该足够了。如果没有,我可以再次编辑。
OVER(orderby(SELECT 0))
可以简化为与您的问题无关的
OVER()
,但是:您应该真正避免那些可怕的引用标识符。他们的麻烦远比他们值得的多。一个基本的方法是我所需要的,我在顶层聚合。我想按照你的建议去做,但我不知道怎么做。再次感谢没有名字的马