gpt4 book ai didi

mysql - 如何显示重复条目的行?

转载 作者:行者123 更新时间:2023-11-29 08:06:34 25 4
gpt4 key购买 nike

我只想获取 newcons 列中具有重复条目的行。在结果中,我想用 recnooldcons 显示整行,并且应该出现 newCons 。我可以使用什么 SQL 查询来执行此操作?

这是我的表格:

RecNo OldB  OldCons    NewCons
1 01 0145501 0008000
2 01 0253801 0107400
3 01 0271200 0000500
4 01 0271201 0012000
5 01 0271202 0000200
6 01 0271300 0000800
7 01 0271301 0001100
8 01 0271302 0002000
9 01 0271303 0001000
10 01 0271304 0001000

应该出现此结果:

RecNo   OldBch  OldSdiv OldCons NewSdiv NewCons
9 01 14433 0271303 14433 0001000
10 01 14433 0271304 14433 0001000

我该怎么做?

最佳答案

此查询将为每个重复项提供一行:

select * from tbl a join tbl b on a.newcons = b.newcons and a.recno > b.recno

要查找重复的 NewCons 值:

select newcons from tbl group by newcons having count(*) > 1

现在,只需将其嵌套到常规 SELECT 中即可:

select * from tbl where newcons in (select newcons from tbl group by newcons having count(*) > 1)

关于mysql - 如何显示重复条目的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22625199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com