Select where count of one field is greater than one

后端 未结 9 1149
说谎
说谎 2020-12-07 23:57

I want to do something like this:

SELECT * 
  FROM db.table 
 WHERE COUNT(someField) > 1

How can I achieve this in MySql?

相关标签:
9条回答
  • 2020-12-08 00:21

    For me, Not having a group by just returned empty result. So i guess having a group by for the having statement is pretty important

    0 讨论(0)
  • 2020-12-08 00:22

    You can also do this with a self-join:

    SELECT t1.* FROM db.table t1
    JOIN db.table t2 ON t1.someField = t2.someField AND t1.pk != t2.pk
    
    0 讨论(0)
  • 2020-12-08 00:27
    SELECT username, numb from(
    Select username, count(username) as numb from customers GROUP BY username ) as my_table
    WHERE numb > 3
    
    0 讨论(0)
提交回复
热议问题