【问题标题】:How to select rows from table 2 based on values in column from table 1 in SQL Teradata?如何根据 SQL Teradata 中表 1 中的列中的值从表 2 中选择行?
【发布时间】:2021-09-07 03:58:57
【问题描述】:

我在 SQL Teradata 中有表:

client              | description
--------------------|-----------
John Simon          |arg John Simon
Larry Foe           |Larry Foe por
Judy Gap            |payment 11 

而且我只需要在“descpition”列中找到它们的名称(来自“client”列)+“arg”或“por”的这些客户端,不管名称之前还是之后。 所以使用上面的例子,我只需要显示 John Simon 和 Larry Fore,因为他们的名字在“description +”arg“或”por”列中,不管是在名字之前还是之后。

我该怎么做?

【问题讨论】:

  • 使用LIKE子句
  • 你能根据我的表格显示整个代码吗?

标签: sql teradata


【解决方案1】:

一种方法是:

where description like '%' || client || '%' and
      (' ' || description || ' ' like '% por %' or
       ' ' || description || ' ' like '% org %'
      )

第二部分中的分隔符只是为了避免匹配“波特兰”之类的名称。

【讨论】:

  • Great Gordon,但是可以管理 "por" 和 "org" 的字母大小吗?因为有时它可能是上而有时不是???
  • @gato 。 . .在后两个比较中使用lower(description)
猜你喜欢
  • 2011-10-25
  • 1970-01-01
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多