我有一张棒球运动员的桌子(全部1000人左右),其中包括:
mysql> describe person; +-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | firstname | varchar(30) | NO | | NULL | | | lastname | varchar(30) | NO | | NULL | | +-----------+-------------+------+-----+---------+----------------+
但是我认为有些球员已经加入了两次。我该如何检查特定姓氏,姓氏组合的出现次数?
这提供了重复项列表:
SELECT firstname, lastname, COUNT(*) FROM person GROUP BY firstname, lastname HAVING COUNT(*) > 1;
如果要查看每一行的计数,请删除hading子句:
SELECT firstname, lastname, COUNT(*) FROM person GROUP BY firstname, lastname;