SQL Query To Obtain Value that Occurs more than once

前端 未结 7 2038
陌清茗
陌清茗 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

    For postgresql:

    SELECT * AS rec 
    FROM (
        SELECT lastname, COUNT(*) AS counter 
        FROM students 
        GROUP BY lastname) AS tbl 
    WHERE counter > 1;
    

提交回复
热议问题