本文介绍了如何选择两列组合相同的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题似乎在描述我的问题上做得很差;让我尝试用一个简化的例子来解释它:
The title seems to do a really poor job at describing my problem; let me try and explain it with a simplified example:
我说我有下表:
_______________________ |id|variant_id|attr_id| |__|__________|_______| |1 |15 |110 | |2 |15 |110 | |3 |20 |152 | |4 |20 |110 | |5 |21 |110 | |__|__________|_______|现在,我想要的是一个查询,该查询选择所有行,其中 variant_id 和 attr_id 列出现多次。基本上在此示例中,它应该选择第1行和第2行,因为它们在 variant_id 和 attr_id 的组合中多次出现
Now, what I'd like to have is a query that selects all rows where a combination of the variant_id and attr_id columns occurs more than once. Basically in this example it should select row 1 and 2, because their combination of variant_id and attr_id occurs more than once in the table.
有可能吗?
推荐答案尝试此查询
SELECT a.* FROM tbl a inner join tbl b ON a.variant_id =b.variant_id AND a.attr_id = b.attr_id WHERE a.id <> b.id;希望这会有所帮助
更多推荐
如何选择两列组合相同的行
发布评论