如何在列中查找单个单词(不是值)的重复项

时间:2018-12-20 07:46:22

标签: sql-server

我想在我的ItemDescription列中找到单个单词的重复项。请看图片:https://imgur.com/oxuaSJT。不是重复的值,而是值中包含单个单词的重复项。可能吗?请帮我。

1 个答案:

答案 0 :(得分:1)

使用GROUP BY运算符查找出现的单词,并使用HAVINGSELECT i.ItemDescription FROM dbo.tbiitems i WHERE i.ItemDescription LIKE '%NR%' OR i.ItemDescription LIKE '%NRCONDITIONER%' OR i.ItemDescription LIKE '%CREAMBATH%' GROUP BY i.ItemDescription HAVING COUNT(i.ItemDescription) > 1 运算符查找重复项:

ItemDescription

或者如果您想查找SELECT i.ItemDescription, COUNT(i.ItemDescription) AS CountItemDescription FROM dbo.tbiitems i WHERE i.ItemDescription LIKE '%NR%' OR i.ItemDescription LIKE '%NRCONDITIONER%' OR i.ItemDescription LIKE '%CREAMBATH%' GROUP BY i.ItemDescription HAVING COUNT(i.ItemDescription) > 1 的计数并遵循 SQL规则 this subject on SO for example(感谢@Daniel E。):

A