简体   繁体   English

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

[英]Teradata SQL - Where clause and conditions depending on conditions

在此处输入图片说明

Note- not all columns are listed here in the Master Table for brevity. 注意-为简洁起见,并非所有列都在主表中列出。 Psuedo code of the where clause - where子句的伪代码-

在此处输入图片说明 在此处输入图片说明

My where clause goes like this (with some selected conditions) - 我的where子句是这样的(在某些选定条件下)-

  1. customer_country in ('A','B','C','D') AND 客户国家(('A','B','C','D')和
  2. ship_country = 'A' AND customer_number <> 'A2' OR ship_country ='A'AND客户编号<>'A2'或
  3. ship_country = 'B' AND customer_number <> 'B2' OR ship_country ='B'AND客户编号<>'B2'或
  4. ship_country = 'C' AND customer_number NOT IN ('C1', 'C2') AND ship_country ='C'AND customer_number NOT IN('C1','C2')AND
  5. ship_date between dates. 日期之间的ship_date。

But this appears to give incorrect answer. 但这似乎给出了错误的答案。 Perhaps something is wrong with the logic. 逻辑上可能有问题。 Please advice. 请指教。

You can try this 你可以试试这个

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'))
    )

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

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