无论如何,我可以使用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 |
答案 0 :(得分:0)
使用分组依据并具有
来显示mysql中所有重复的值
有多种方法可以执行此操作,但是,如果要使用group by
和having
,则可以将表与标识重复项的聚合子查询联接起来,如下所示:< / p>
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