Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.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(Omnisci)获取列的公共值和非公共值_Sql_Omniscidb - Fatal编程技术网

SQL(Omnisci)获取列的公共值和非公共值

SQL(Omnisci)获取列的公共值和非公共值,sql,omniscidb,Sql,Omniscidb,我正在使用Omnisci连接两个表,我需要以下内容: 表1: poly_id | num_competitors 1 | 1 2 | 1 3 | 5 表2: poly_id | num_stores 1 | 1 5 | 3 7 | 5 我想要的是: poly_id | num_competitors | num_stores

我正在使用Omnisci连接两个表,我需要以下内容:

表1:

poly_id | num_competitors
   1    |     1
   2    |     1
   3    |     5
表2:

    poly_id | num_stores
       1    |     1
       5    |     3
       7    |     5
我想要的是:

 poly_id | num_competitors | num_stores
       1    |     1        |    1
       2    |     1        |    0
       3    |     5        |    0
       5    |     0        |    3
       7    |     0        |    5

我知道在普通SQL中,您可以使用完全联接,甚至使用UNION,但Omnisci还不支持这些函数中的任何一个(尽管它支持联接和左联接)。

我找到了一种解决方法。这是通过创建一个新的空表来实现的。将表1和表2插入其中,然后在poly id上创建一个groupby,以便合并同时具有num_竞争对手和num_存储的行

CREATE TABLE competitors_stores ( poly_id integer, num_stores integer, num_competitors integer);

INSERT INTO competitors_stores ( SELECT poly_id, 0, num_competitors from competitors_geo)

INSERT INTO competitors_stores ( SELECT poly_id, num_stores, 0 from telepi_stores_geo)

CREATE TABLE num_competitors_stores AS (select poly_id, SUM(num_stores) AS num_stores, SUM(num_competitors) as num_competitors from competitors_stores group by poly_id);

DROP TABLE telepi_competitors_stores;

无论如何,我仍然愿意听取其他选择,因为我觉得这不是解决问题的最佳方法。

如果它不支持
联合
,他们怎么称呼它为“SQL”?我猜他们依赖于这样一个事实,即数据的结构与SQL一样是关系的,并且它支持SQL提供的大部分功能。问题是,这是一个被认为可以解决地理空间和大数据问题的工具(它还支持PostGIS的大部分功能),因此他们可能会避免实现
UNION
,因为这可能会非常低效。如果您想了解更多信息,可以查看他们的文档