mysql - 如何在 MySQL 中的另一列中共享相同值的表中返回重复项?
问题描述
我将如何返回相同年份的数字重复的 ProductNumbers ?这都在同一个表中。在下面的示例中,我希望返回 ProductNumber 123 和 456。如有可能请说明理由,谢谢!
ProductNumber Numb Year
123 45 1
456 45 1
789 45 2
109 54 2
解决方案
这是使用的一个选项exists
:
select *
from yourtable t
where exists (
select 1
from yourtable t2
where t.productnumber != t2.productnumber
and t.numb = t2.numb
and t.year = t2.year
)
使用exists
,我们检查同一个表中是否有其他记录productnumber
不同,但具有相同的numb
和year
值。
推荐阅读
- javascript - 将长 JS 计算分解成碎片 - 奇怪的 Chrome 行为
- python - 为什么通过改变打印语句的位置,在斐波那契模式中,在递归中,输出的顺序会改变?
- td-engine - 在 TDengine 中使用 taosdump 进行数据迁移
- javascript - 从 MongoDB 中获取价值
- flutter - 如何在 listview.separated Flutter 中的第一项和 appbar 之间留出空间
- ios - 是否可以观察 SwiftUI 视图的工具栏的 alpha?
- scala - 了解使用路径依赖类型来模拟存在量化类型
- javascript - 在条形图js中显示%登录
- c - 当前 CPU 核心利用率通过 /proc/stat
- vim - 如何将连续命令映射到键