我有以下 sql 需要很长时间才能执行,有没有更好的方法来编写它来提高速度。
任何帮助都是非常可观的。
谢谢
SELECT a.KeyField
FROM Details a,
Master b
WHERE a.ForeignKeyField = b.ForeignKeyField
AND a.KeyField IS NOT NULL
AND Date BETWEEN
TO_DATE ('01-01-2011', 'dd-mm-yyyy') AND TO_DATE ('31-12-2011', 'dd-mm-yyyy')
AND a.KeyField IN
(SELECT p.KeyField
FROM Details p,
Master q
WHERE q.ForeignKeyField = p.ForeignKeyField
AND p.KeyField IS NOT NULL
AND p.KeyField = a.KeyField
AND q.FKField2 = b.FKField2
GROUP BY p.KeyField,
q.Date HAVING COUNT (DISTINCT q.ForeignKeyField) > 1)
GROUP BY b.Id,
b.Name,
b.ForeignKeyField,
b.Date,
a.ForeignKeyField,
a.SomeOtherField,
a.KeyField,
b.EtcEtc