【问题标题】:Teradata SQL - Where clause and conditions depending on conditionsTeradata SQL - Where 子句和条件取决于条件
【发布时间】:2018-08-06 19:47:49
【问题描述】:

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

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

  1. customer_country in ('A','B','C','D') 和
  2. ship_country = 'A' AND customer_number 'A2' OR
  3. ship_country = 'B' AND customer_number 'B2' OR
  4. ship_country = 'C' AND customer_number NOT IN ('C1', 'C2') AND
  5. ship_date 日期之间。

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

【问题讨论】:

  • 编辑您的问题,而不是将有价值的信息作为 cmets。
  • 感谢 jarlh,听从了您的建议
  • where not (ship_country = 'A' and customer_number = 'A2') and not (...
  • 我收到此错误消息 - 执行为多个语句。声明 1:数据库已完成。已处理 0 行。已用时间 = 00:00:00.531 语句 2:选择语句失败。失败 [3134 : HY008] 请求被 ABORT SESSION 命令中止。
  • customer_country 在您的master 表中的哪个位置?

标签: sql conditional-statements teradata where-clause


【解决方案1】:

你可以试试这个

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

【讨论】:

    猜你喜欢
    • 2018-08-07
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2016-10-16
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    相关资源
    最近更新 更多