Teradata SQL - 条件取决于WHERE子句中的条件

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

这个问题是旧帖子的变体 enter image description here

条件

如果Customer_country ='A'

  1. 那么Ship_country必须='A'
  2. 和Customer_number <>'A2'(即排除A2)
  3. 和日期在x和y之间。 (对所有客户国家都一样)

所有Customer_country都采用相同的逻辑,其中排除了相应的B2,C2,D2 Customer_numbers。

enter image description here

我对使用CASE ... WHEN感到困惑,因为它预计会返回一个值。 但我没有回报任何价值。请帮助解决此问题。

sql teradata where-clause case-when
1个回答
1
投票

您应该使用where子句而不是case when

使用||方法组合char,如A2B2 ...,然后你可以排除它。

SELECT *
FROM master as t1 
WHERE 
    t1.Customer_number <> t1.Customer_Country || '2'
AND 
    t1.Ship_Country = t1.Customer_Country

teradata ||

编辑

如果customer_number类似于'981432776',您可以使用NOT IN来排除它。

SELECT *
FROM master as t1 
WHERE 
    t1.Customer_number NOT IN ('A2','B2','C2','D2')
AND 
    t1.Ship_Country = t1.Customer_Country
© www.soinside.com 2019 - 2024. All rights reserved.