SQL:查找字段中的重复值,但使用 SubString()
这里有一个问题要问所有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许
Perhaps