MySQL - 在 WHERE 子句中使用 COUNT(*)

2021-11-20 00:00:00 count aggregation mysql having

我正在尝试在 MySQL 中完成以下操作(请参阅 pseudo 代码)

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

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

有没有办法在 WHERE 子句中不使用 (SELECT...) 来做到这一点,因为这看起来像是在浪费资源.

Is there a way to do this without using a (SELECT...) in the WHERE clause because that would seem like a waste of resources.

推荐答案

试试这个;

select gid
from `gd`
group by gid 
having count(*) > 10
order by lastupdated desc

相关文章