根据 PL/SQL 中字符串的前 n 个字符查找重复项
Finding duplicates based on first n characters of a string in PL/SQL
我是论坛的新手,SQL,我希望这是一个容易回答的问题。我正在使用 Oracle 数据库,我想通过仅搜索公司名称字符串中的前 10 个左右字符来搜索 table 中的重复公司。
例如:如果我在 table 中分别列出了 'ABC Corp'
、'ABC Co'
和 'ABC Corporation'
,我希望能够搜索 'ABC C'
并让所有公司 returned。由于我正在寻找重复项,因此我只想 return 子字符串出现不止一次的结果。看起来应该很容易,但我无法让它工作。
有什么建议吗?
谢谢
这将为您提供在 table:
中多次出现的所有子字符串的列表
select
substr(name, 0, 6),
count(substr(name, 0, 6))
from test
group by substr(name, 0, 6)
having count(substr(name, 0, 6)) > 1
和这个 returns 子字符串出现不止一次的公司列表:
select
name
from test test1
where (
select count(*)
from test
where substr(test.name, 0, 6) = substr(test1.name, 0, 6)) > 1
我是论坛的新手,SQL,我希望这是一个容易回答的问题。我正在使用 Oracle 数据库,我想通过仅搜索公司名称字符串中的前 10 个左右字符来搜索 table 中的重复公司。
例如:如果我在 table 中分别列出了 'ABC Corp'
、'ABC Co'
和 'ABC Corporation'
,我希望能够搜索 'ABC C'
并让所有公司 returned。由于我正在寻找重复项,因此我只想 return 子字符串出现不止一次的结果。看起来应该很容易,但我无法让它工作。
有什么建议吗?
谢谢
这将为您提供在 table:
中多次出现的所有子字符串的列表select
substr(name, 0, 6),
count(substr(name, 0, 6))
from test
group by substr(name, 0, 6)
having count(substr(name, 0, 6)) > 1
和这个 returns 子字符串出现不止一次的公司列表:
select
name
from test test1
where (
select count(*)
from test
where substr(test.name, 0, 6) = substr(test1.name, 0, 6)) > 1