用于获取重复项的SQL查询

时间:2017-12-14 15:58:02

标签: sql

我有下表

people
person_id
first_name
last_name

我想抓取姓氏多次出现的所有人。 有人可以帮我这个。

2 个答案:

答案 0 :(得分:0)

选择

PERSON_ID,
姓氏,

FIRST_NAME:

COUNT(*)

People

GROUP BY

Person_id,Last_Name,First_Name

HAVING

COUNT(*) > 1

答案 1 :(得分:-1)

Select *
from persons t1
Join (select t2t1. lastName, count(t2t1. *) 'counted' 
          from persons t2t1
          Group by t2t1. lastName
          Having count(t2t1. *) >1
     ) t2 on t1.LastName=t2. Lastname