我想看看对公共汽车的预计到达时间所做的预测是否有实际的信息。我写了这个查询,它超时了。难道我做错了什么?有什么优化在这里有帮助吗?
SELECT
P.ROUTE,
P.CODE,
(
SELECT COUNT(*)
FROM MESSAGE M
WHERE M.SENTDATE BETWEEN P.ARRIVAL-(20/60/24) AND P.ARRIVAL+(2/60/24)
AND TRIM(SUBSTR(M.LOCATIONINFO, 3, 10)) = P.ROUTE
AND TRIM(SUBSTR(M.LOCATIONINFO, 25, 10)) = P.CODE
)
CNT
FROM
(
SELECT *
FROM PREDICTION P
WHERE P.ARRIVAL BETWEEN TO_DATE('2012/07/04 04:30:00', 'YYYY/MM/DD HH24:MI:SS')
AND TO_DATE('2012/07/04 04:30:10', 'YYYY/MM/DD HH24:MI:SS')
AND P.ROUTE ='7'
AND P.CODE ='2179'
)
P