mysql - 如何显示所有重复值
问题描述
无论如何我可以使用 group by 显示 mysql 中的所有重复值并拥有
+---------+--------------+------------+--------+----------+----------+---------+
| ENumber | EmpName | Birthdate | Gender | Address | Salary | DNumber |
+---------+--------------+------------+--------+----------+----------+---------+
| E001 | GSInocencio | 1988-01-15 | F | Munoz | 18000.00 | D005 |
| E002 | EAVillanueva | 1988-04-20 | F | Munoz | 23000.00 | D003 |
| E003 | ALedesma | 1988-05-25 | M | CLSU | 21000.00 | D002 |
| E004 | APGamilla | 1991-10-15 | F | Maligaya | 25000.00 | D001 |
| E005 | ACTolentino | 1989-02-20 | F | Maligaya | 30000.00 | D002 |
| E006 | ANVillasoto | 1999-01-05 | M | CLSU | 15000.00 | D004 |
| E007 | JPPalada | 1997-01-10 | M | Munoz | 21000.00 | D001 |
| E008 | NTNicodemus | 1995-04-15 | F | Maligaya | 22000.00 | D003 |
+---------+--------------+------------+--------+----------+----------+---------+
我想在 DNumber 中显示所有重复值
+---------+--------------+------------+--------+----------+----------+---------+
| ENumber | EmpName | Birthdate | Gender | Address | Salary | DNumber |
+---------+--------------+------------+--------+----------+----------+---------+
| E004 | APGamilla | 1991-10-15 | F | Maligaya | 25000.00 | D001 |
| E007 | JPPalada | 1997-01-10 | M | Munoz | 21000.00 | D001 |
| E003 | ALedesma | 1988-05-25 | M | CLSU | 21000.00 | D002 |
| E005 | ACTolentino | 1989-02-20 | F | Maligaya | 30000.00 | D002 |
| E002 | EAVillanueva | 1988-04-20 | F | Munoz | 23000.00 | D003 |
| E008 | NTNicodemus | 1995-04-15 | F | Maligaya | 22000.00 | D003 |
解决方案
display all the duplicate values in mysql using group by and having
There is more than one way to do it, but if you want to use group by
and having
, then you can join the table with an aggregate subquery that identifies the duplicates, as follows:
select t.*
from mytable t
inner join (
select dnumber
from mytable
group by dnumber
having count(*) > 1
) x on x.dnumber = t.dnumber
order by t.dnumber, t.enumber
推荐阅读
- android - 登录webview中Android空白页面上的MS OAuth2 - 如果我破坏配置,它将在webview中显示错误并工作
- sql - SQL Server 表计算到特殊列
- java - 正则表达式匹配直到Java中的文本结尾
- linux - 使用 gcc/ld/cmake 链接到特定的 .so 版本,拒绝其他版本
- batch-file - Windows 10 批处理文件:在以前版本中工作的文件的奇怪行为
- gcc - 汇编代码生成 SEGMENTATION FAULT
- xbee - XBee3 协调器在网络发现期间找不到 End_Device
- java - Java 自动装箱 int 到 Long
- postgresql - 无法使用通过 ansible 创建的 postgresql 用户登录
- ios - didWriteValueFor 在尝试使用 .writeValue 写入时未第二次调用