如何选择两列组合相同的行

编程入门 行业动态 更新时间:2024-10-11 17:25:20
本文介绍了如何选择两列组合相同的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

标题似乎在描述我的问题上做得很差;让我尝试用一​​个简化的例子来解释它:

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;

希望这会有所帮助

更多推荐

如何选择两列组合相同的行

本文发布于:2023-11-22 02:03:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   如何选择

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!