繁体   English   中英

成对列比较的“NOT IN”/“NOT EXISTS”在 Redshift 中不起作用

[英]"NOT IN"/"NOT EXISTS" for pairwise column comparison not working in Redshift

我想用 redshift 重写下面的语句。 Redshift 不支持 IN/NOT IN 进行多列比较。 当我也使用 NOT EXISTS 尝试相同的查询时,出现以下错误:

无效操作:由于内部错误,不支持此类相关子查询模式;

select count(distinct item) from tbl1  
where (item,store) not in (
select distint item, store form tbl1 
where *store changed* -- some filters
)

Tim 的想法似乎很酷,但您也可以使用以下代码:

select     count(distinct t1.item)
from       tbl1 t1
left join
(
        select distinct item, store
        form   tbl1 
        where  *store changed* -- some filters
) t2
on t2.item = t1.item
and t2.store = t1.store

where t2.item is null
and   t2.store is null

您的 Redshift 版本不支持此元组语法。 您可以改写如下:

SELECT COUNT(DISTINCT item) AS cnt
FROM tbl1 t1
WHERE NOT EXISTS (
    SELECT 1
    FROM tbl1 t2
    WHERE t2.item = t1.item AND
          t2.store = t1.store AND
          (other filters here...)
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM