0

我在 Teradata SQL 表中,如下所示:

col1             | col2
----------------------------
Adam Nowak PHU   | Nowak Adam
AAR Kowal Jan    | Kowal Jan
Tomasz Gut       | Juk Anna

我只想选择以下行:

  • 在 col1 我有来自 col2 + 东西的价值(没关系之前或之后的价值)
  • 请注意,姓名和姓氏的顺序并不重要,因此 Jan Kowal 与 Kowal Jan 相同

因此,我需要像下面这样的东西,所以只有第一行和第二行,因为 col2 中有 col1 值 + 其他东西,名字和姓氏的顺序并不重要:

在此处输入图像描述

  1. 我使用了如下查询,但我的查询没有考虑到姓名顺序并不重要,并且对于我的代码 Jan Kowal 和 Kowal Jan 是不同的人。
where upper(col1) like '%' || upper(col2) || '%'
  1. 此外,我使用的代码非常适合我的情况并且可以正常工作,但仅在 SQL Server 上,在 Teradata SQL id 上不起作用:
WHERE
      upper(col1) LIKE '%' + substring(upper(col2), 1, CHARINDEX(' ',col2)-1) + '%'

    AND

      upper(col1) LIKE '%' + substring(upper(col2), CHARINDEX(' ',col2)+1, LEN(col2)) + '%'
  1. 我在 Teradata 代码上更改了它,如下所示:
WHERE
  upper(col1) LIKE '%' || substr(upper(col2), 1, nullifzero(index(' ',col2)-1)) || '%'

AND

  upper(col1) LIKE '%' || substr(upper(col2), nullifzero(index(' ',col2)+1, length(col2))) || '%'

但是上面的代码会产生错误:

SUBSTR:字符串订阅超出范围

  1. 我还尝试了以下方法:
where position(strtok(col2, ' ', 1) in col1) > 0   and position(strtok(col2, ' ', 2) in col1) > 0

但它会产生错误:

STRTOK:InputString或Delim长度为0;或 toknum 参数不大于 0,

我能做些什么?请帮帮我。

如何在 Teradata SQL 中做到这一点?您能否修改我在 SQL Server 上工作的代码或建议您自己在 Teradata SQL 上工作的解决方案?

4

1 回答 1

0

我想你想要regexp_similar()

where regexp_similar(col1, replace(col2, ' ', '|') = 1
于 2021-07-02T22:31:19.390 回答