【问题标题】:Joining based on a condition in Teradata基于 Teradata 中的条件加入
【发布时间】:2020-10-02 10:35:54
【问题描述】:

我正在尝试写如下内容:

case when table_1.account_or_client='A' then inner join on table_1.addr_id=table_2.addr_id where substr(table_2.addr_id,2,1) is not 0
else then inner join on table_1.addr_id=table_2.addr_id

但语法正确。我该怎么做?

当table_1.account_or_client='A'时,join时需要确保table_2.addr_id的第二位不为0

【问题讨论】:

  • 请提供样本数据和期望的结果。显然你的代码 sn-p 不是正确的 SQL,很容易被误解。

标签: sql join conditional-statements teradata where-clause


【解决方案1】:

当 table_1.account_or_client='A' 转换为时,我需要确保 table_2.addr_id 的第二位不为 0

FROM table_1 AS t1 
JOIN table_2 AS t2
  ON t1.addr_id=t2.addr_id
 AND NOT (t1.account_or_client='A' AND Substr(t2.addr_id,2,1) = '0')

【讨论】:

    猜你喜欢
    • 2018-10-27
    • 1970-01-01
    • 2012-12-08
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    相关资源
    最近更新 更多