【发布时间】:2016-08-03 12:23:54
【问题描述】:
我在 Netezza 有 3 张桌子。
表 1:商店
CREATE TABLE STORES
(
STORE_NAME CHARACTER VARYING(10),
STORE_TYPE CHARACTER VARYING(10)
);
表 2:城市
CREATE TABLE CITIES
(
CITY CHARACTER VARYING(10)
);
表 3:CITIES_STORES
CREATE TABLE CITIES_STORES
(
STORE_TYPE CHARACTER VARYING(10),
CITY CHARACTER VARYING(10)
);
我需要找到所有城市都有的 store_type。所以我试图通过以下方式做到这一点。如果对于一个特定的,
store_type(存在于Stores 表中),我找不到store_type 不存在的任何状态,那么store_type 就是我的答案。
我编写了以下查询并在 Netezza 中运行:
select distinct
store_type
from
stores
where
not exists (
select *
from
cities
where
not exists (
select *
from
cities_stores
where
cities_stores.city = cities.city
and cities_stores.store_type = stores.store_type
)
);
但它给出了一个错误
错误:(2) 不支持这种形式的相关查询 - 考虑 重写
请告诉我哪里出错了。这是 Netezza 数据库的问题吗?
【问题讨论】:
标签: sql netezza correlated-subquery not-exists nested-query