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秒。
答案 0 :(得分: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;
答案 1 :(得分:0)
无需在WHERE
子句中使用该查询。您可以使用GROUP BY
和HAVING
子句来完成此任务:
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
答案 2 :(得分: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;