0

我有包含以下列的 EMP 表:

EmpID
firstName
LastName
Age
DOB
status

如何获得具有相同名字和姓氏的所有员工

4

1 回答 1

0

It depends what you want your output to look like

SELECT firstName, lastName, count(*)
  FROM emp
 GROUP BY firstName, lastName
HAVING COUNT(*) > 1

will show you all the firstName and lastName pairs that are duplicated. If you want to get the empID of both duplicated rows (assuming neither firstName nor lastName can be NULL)

SELECT a.empID, b.empID
  FROM emp a,
       emp b
 WHERE a.firstName = b.firstName
   AND a.lastName  = b.lastName
   AND a.rowid     > b.rowid
于 2012-04-04T15:51:26.710 回答