MySQL - Using COUNT(*) in the WHERE clause

前端 未结 9 1707
不思量自难忘°
不思量自难忘° 2020-11-28 20:55

I am trying to accomplish the following in MySQL (see pseudo code)

SELECT DISTINCT gid
FROM `gd`
WHERE COUNT(*) > 10
ORDER BY lastupdated DES         


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 21:45

    SELECT COUNT(*)
    FROM `gd`
    GROUP BY gid
    HAVING COUNT(gid) > 10
    ORDER BY lastupdated DESC;
    

    EDIT (if you just want the gids):

    SELECT MIN(gid)
    FROM `gd`
    GROUP BY gid
    HAVING COUNT(gid) > 10
    ORDER BY lastupdated DESC
    

提交回复
热议问题