snowflake 和 redshift 中的相同查询获取不同的结果为什么?

问题描述 投票:0回答:1

Redshift 中的相同查询仅获取 18 条记录,但在雪花中它获取 27k 条记录。我不知道为什么......即使两个数据库中的数据相同。背后的原因是什么 这是查询

SELECT CUR.datasource
       , CUR.reqid
       , CUR.respid
       , CUR.caseno
       , CUR.category
       , CUR.topic
       , CUR.contact_type
       , CUR.division
       , CUR.gender
       , CUR.city
       , CUR.region
       , CUR.country
       , CUR.entrydate_loc
       , CUR.entrydate_loc_month
       , CUR.product_name
       , CUR.product_description
       , CUR.req_mode
       , CUR.languages
       , CUR.CODE
       , CUR.CODE_ORIG
       , CUR.dept
       , CUR.inquiry_text
       , CUR.subregion
       , CUR.subregion_amer_la
       , CUR.therapeutic_area
       , CUR.ae_flag
       , CUR.pc_flag
       , CUR.facilitator_flag
       , CUR.resolution
       , CUR.inbound_channel1
       , CUR.inbound_channel2
       , CUR.state_or_region
       , CUR.specialty
       , cur.load_date
 FROM team_incite.gmi_grace_prima_temp CUR
 full outer join team_incite.gmi_grace_translated PREV
  ON CUR.REQID=PREV.REQID AND CUR.RESPID=PREV.RESPID
 WHERE PREV.REQID IS NULL AND PREV.RESPID IS NULL   

我已经检查了 redshift 和 snowflake 中的两个表,它们返回相同的计数

select count(*) from team_incite.gmi_grace_translated;
select count(*) from team_incite.gmi_grace_prima_temp;

有人知道少了什么吗?

我想知道根本原因

sql snowflake-cloud-data-platform amazon-redshift
1个回答
0
投票

我怀疑问题出在您的 ON 条款中。在 Redshift 中,您无法测试 NULL = NULL,它永远不会为真。由于您的 WHERE 子句要求这些值为 NULL,因此您不能每次都匹配,因此您只能在 Redshift 中获得 OUTER 部分。我不知道你的数据,所以我不能确定,但这需要重写才能做你想做的事。像这样的东西:

SELECT CUR.*
FROM team_incite.gmi_grace_prima_temp CUR
full outer join team_incite.gmi_grace_translated PREV
  ON (CUR.REQID=PREV.REQID OR (CUR.REQID IS NULL AND PREV.REQID IS NULL))
 AND (CUR.RESPID=PREV.RESPID OR (CUR.RESPID IS NULL AND PREV.RESPID IS NULL))
WHERE PREV.REQID IS NULL AND PREV.RESPID IS NULL
© www.soinside.com 2019 - 2024. All rights reserved.