使用内部加入删除倒数/类似记录
我有一个带有名字的桌子,其中一些是对其他人的速记,有些是相似的,但不相似。例如,Michael 和Mike
是相互的,但Michael
不是。我运行了一个脚本以获得一匹或双向匹配的脚本,例如
Michael | Mike
Mike | Michael
,这只是
Michael | Uncle Michael
表明它们不匹配对。
我正在尝试使用它来删除较短的匹配项(例如Mike
)。
我有一个 sqlfiddle,证明了这一点,我只能找到匹配的对,但是,不确定现在如何进行删除T1
以从所有匹配对中删除发现的记录的较短。
I have a table with names, some of which are shorthand for others and some which are similar but are not. For instance Michael
and Mike
are reciprocal, yet Uncle Michael
is not. I ran a script to get the either one- or two-way matching e.g.
Michael | Mike
Mike | Michael
yet only
Michael | Uncle Michael
which indicates they are not matching pairs.
I'm trying to use that to then remove the shorter matching term (e.g. Mike
).
I have a SqlFiddle demonstrating this, I can get as far as finding only the matching pairs but am unsure how to now do a Delete t1
to delete the shorter of the found record from all of the matching pairs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能会从数据库服务器的角度为您提供一些见解。我们可以通过子句使用
组来为名称中定义的组名称。例如“迈克”和“迈克尔”。然后,我们计算结果集中不同名称的数量。如果存在超过1个不同的名称,我们删除了较短的名称。否则,否则没有任何删除,因为我们可能要保留的只有1个不同的名称。
This might give you some insight from db server's perspective. We can use a
group by
clause to group names defined in a name-pair. e.g 'Mike' and 'Michael'. Then we count the number of distinct names in the result set . In the case when more than 1 distinct name exists, we delete the shorter one. Otherwise delete nothing as there is only 1 distinct name existing which we probably want to keep.