2
SELECT COUNT(organization.ID) 
FROM organization 
WHERE name in ( SELECT name FROM organization GROUP BY name HAVING count( name ) >1 )
AND organization.APPROVED=0 
AND organization.CREATED_AT>'2010-07-30 10:30:21'

我正在尝试查找重复项,但此查询需要很长时间,大约 5-6 秒。有没有另一种方法可以在不使用我的方法的情况下找到重复项?谢谢。

子查询:0.28 秒。一切都是 5.98 秒。

4

3 回答 3

1
SELECT organization.name, COUNT(organization.ID)
  FROM organization
 WHERE organization.APPROVED=0
   AND organization.CREATED_AT>'2010-07-30 10:30:21'
 GROUP BY name
HAVING count(organization.id) > 1;
于 2012-07-30T14:24:17.260 回答
0

无需在WHERE子句中使用查询。您可以使用 a GROUP BYand aHAVING子句来完成此操作:

SELECT COUNT(o.ID) 
FROM organization o
WHERE o.APPROVED=0 
   AND o.CREATED_AT>'2010-07-30 10:30:21'
GROUP BY o.Name
HAVING COUNT(o.name) > 1
于 2012-07-30T14:25:33.547 回答
0

为什么不这样做:

SELECT COUNT(organization.ID)
FROM organization 
WHERE organization.APPROVED=0 
AND organization.CREATED_AT>'2010-07-30 10:30:21'
GROUP BY organization.name
HAVING count(organization.name) > 1;
于 2012-07-30T14:25:37.527 回答