MySQL - Using COUNT(*) in the WHERE clause

前端 未结 9 1705
不思量自难忘°
不思量自难忘° 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:53

    COUNT(*) can only be used with HAVING and must be used after GROUP BY statement Please find the following example:

    SELECT COUNT(*), M_Director.PID FROM Movie
    INNER JOIN M_Director ON Movie.MID = M_Director.MID 
    GROUP BY M_Director.PID
    HAVING COUNT(*) > 10
    ORDER BY COUNT(*) ASC
    

提交回复
热议问题