【发布时间】:2019-06-27 03:13:06
【问题描述】:
我正在尝试使用根据某些 case 语句而变化的 join 语句。当字段 lane.dest_postal_code_prefix 不是 NULL 时,我希望连接类似于下面的第一个代码块。 当字段 lane.dest_postal_code_prefix 为 NULL 时,我希望连接类似于下面的第二个代码块。 (注意两种情况下ON条件的区别)
我需要一些帮助,将 case 语句添加到 join 子句中。
--WHEN lane.dest_postal_code_prefix is NOT NULL
SELECT * FROM big_bucket_bridge A
LEFT JOIN lane
ON
(
A.customer_country = lane.dest_country_code
AND
SUBSTRING( A.ddm_zip, 1, LENGTH( lane.dest_postal_code_prefix ) ) =
lane.dest_postal_code_prefix
)
WHERE
snapshot_day between '2019-06-23'-22 and '2019-06-23'
AND (is_before_cutoff_g OR (is_before_cutoff_opt_g and not under_two))
AND row_n =1
;
--WHEN lane.dest_postal_code_prefix is NULL
SELECT * FROM big_bucket_bridge A
LEFT JOIN lane
ON
(
A.customer_country = lane.dest_country_code
)
WHERE
snapshot_day between '2019-06-23'-22 and '2019-06-23'
AND (is_before_cutoff_g OR (is_before_cutoff_opt_g and not under_two))
AND row_n =1
;
【问题讨论】: