-1

以下是我的查询,我在包含超过 91000 条记录的表上执行我的 sql。

select l.* 
from localcdrsmem l 
LEFT JOIN (
         SELECT LocalCDRID, ForeignCDRsID 
         from localcdrsmem l 
         INNER JOIN foreigncdrsmem f 
         ON l.CalledNumber=f.CalledNumber and 
         ABS(l.Duration-f.Duration)<= 2 and            
         ABS(TIMESTAMPDIFF(SECOND,f.StartTime,l.StartTime))<=100 
         group by l.CalledNumber) 
as temp ON l.LocalCDRID = temp.LocalCDRID 
where temp.LocalCDRID IS NULL;

表是:

localcdrsmem - > 
+---------+------------+--------+----------
localcdrid | callednumber | duration | starttime
+---------+------------+--------+----------+
foreigncdrsmem- > 
+------------+------------+--------+----------
foreigncdrid | callednumber | duration | starttime
+---------+------------+--------+----------+

优化此查询的任何想法?

4

1 回答 1

-1
select l.* from localcdrsmem l LEFT JOIN 
(SELECT LocalCDRID, ForeignCDRsID from localcdrsmem l 
INNER JOIN foreigncdrsmem f
ON l.CalledNumber=f.CalledNumber 
WHERE ABS(l.Duration-f.Duration)<= 2 
and ABS(TIMESTAMPDIFF(SECOND,f.StartTime,l.StartTime))<=100 
group by l.CalledNumber) as temp
ON l.LocalCDRID = temp.LocalCDRID where temp.LocalCDRID IS NULL;

试试上面的这个查询。此查询执行得更快。只需在此语句之后更改and带有where子句的语句ON l.CalledNumber=f.CalledNumber。您可以看到我们的查询之间的区别。

于 2013-09-09T08:16:05.657 回答