Teradata SQL - Where 子句和条件取决于条件

Teradata SQL - Where clause and conditions depending on conditions

注意 - 为简洁起见,并非所有列都列在 Master Table 中。 where子句的伪代码-

我的 where 子句是这样的(有一些选定的条件)-

  1. customer_country 在 ('A','B','C','D') 和
  2. ship_country = 'A' 和 customer_number <> 'A2' 或
  3. ship_country = 'B' 和 customer_number <> 'B2' 或
  4. ship_country = 'C' AND customer_number 不在 ('C1', 'C2') AND
  5. ship_date 日期之间。

但这似乎给出了错误的答案。也许逻辑有问题。请指教

你可以试试这个

SELECT * 
FROM [MASTER]
WHERE 
    Ship_country in ('A','B','C','D')
AND
    (   
        (customer_number <> 'A2')
    OR
        (customer_number <> 'B2')
    OR
        (customer_number NOT IN ('C1', 'C2'))
    )