SQL Query To Obtain Value that Occurs more than once

前端 未结 7 1985
陌清茗
陌清茗 2020-12-08 19:26

I need to query my database to show the records inside my table where lastname occurs more than three times. Example: in my Students Table, there are 3 people with Lastname

7条回答
  •  时光说笑
    2020-12-08 19:43

    I think this answer can also work (it may require a little bit of modification though) :

    SELECT * FROM Students AS S1 WHERE EXISTS(SELECT Lastname, count(*) FROM Students AS S2 GROUP BY Lastname HAVING COUNT(*) > 3 WHERE S2.Lastname = S1.Lastname)
    

提交回复
热议问题