SQL:查找字段中的重复值,但使用 SubString()

发布于 2024-09-14 02:22:56 字数 640 浏览 8 评论 0原文

这里有一个问题要问所有 SQL SERVER 2000 专家:

我只有 1 个表...我已经可以找到某个字段中的任何值是否也出现在另一条记录中。

IE:是否有任何记录 字段中的“ABCDEFGHI”,然后 再次“ABCDEFGHI” 字段...但在另一条记录中。

但是当我尝试使用子字符串时遇到了麻烦。

IE:任何记录中是否有“CDEF” 一个字段,然后再次“DEFG” 同一领域...但在另一条记录中。 (编辑:当然,这不会匹配。)

我正在尝试将 1 个字段的部分与另一个字段的部分进行比较。 仅将字符 3-6 与字符 4-7 进行比较。 (我需要为这两个字段指定我自己的开始结束范围。) 具体字母是什么...并不重要。只是他们“匹配”。

这似乎不起作用:(

SELECT t1.ID + ' + ' + t2.ID  
FROM InfoTable As t1         
INNER JOIN InfoTable AS t2     ON t1.ID = SUBSTRING(t2.ID, 3, 4) 

编辑:我还需要不列出任何仅与自身匹配的记录。)

Here's a question for all those SQL SERVER 2000 experts:

I have only 1 table... I can already find if any of the values in a certain field, also appears in another record.

I.E.: Does any record have
"ABCDEFGHI" in a field, and then
"ABCDEFGHI" again in that same
field... but in another record.

But I run into trouble when I try to use substrings.

I.E.: Does any record have "CDEF" in
a field, and then "DEFG" again in that
same field... but in another record.
(Edit: That would NOT be a match, of course.)

I'm trying to compare PART of 1 field, with PART of another.
Only compare characters 3-6 characters, with characters 4-7.
(I need to specify my own start-end ranges, for both fields.)
What the specific letters are... doesn't matter. Just that they 'match'.

This doesn't seem to work:

SELECT t1.ID + ' + ' + t2.ID  
FROM InfoTable As t1         
INNER JOIN InfoTable AS t2     ON t1.ID = SUBSTRING(t2.ID, 3, 4) 

(Edit: I also need to NOT list any records that are just matching themselves.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2024-09-21 02:22:56

也许

SELECT t1.ID + ' + ' + t2.ID  
FROM InfoTable As t1         
INNER JOIN InfoTable AS t2     ON SUBSTRING(t1.ID,3,6) = SUBSTRING(t2.ID, 4, 7) 

Perhaps

SELECT t1.ID + ' + ' + t2.ID  
FROM InfoTable As t1         
INNER JOIN InfoTable AS t2     ON SUBSTRING(t1.ID,3,6) = SUBSTRING(t2.ID, 4, 7) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文