- 论坛徽章:
- 0
|
我有这么一条语句:
SELECT 200505, 'AR', 'AR_FROZEN', edate, ardpfx
|| rinvc, SUM (rcamt) amt
FROM acrrar
WHERE rrid = 'RI'
AND ardpfx
|| rinvc IN (SELECT rinvc
FROM (SELECT ardpfx
|| rinvc rinvc,
SUM (rcamt) * (-1) amt
FROM acrrar
WHERE rrid = 'RI' AND edate = 20050225
GROUP BY ardpfx, rinvc
UNION
SELECT ardpfx
|| rinvc rinvc,
SUM (rcamt) amt
FROM acrrar
WHERE rrid = 'RI' AND edate = 20050325
GROUP BY ardpfx, rinvc)
GROUP BY rinvc
HAVING SUM (amt) <>; 0)
AND edate IN (20050225, 20050325)
GROUP BY edate, ardpfx, rinvc
运行起来,n长时间也跑不出来;
如果把rrid = 'RI'去掉,
SELECT 200505, 'AR', 'AR_FROZEN', edate, ardpfx
|| rinvc, SUM (rcamt) amt
FROM acrrar
WHERE ardpfx
|| rinvc IN (SELECT rinvc
FROM (SELECT ardpfx
|| rinvc rinvc,
SUM (rcamt) * (-1) amt
FROM acrrar
WHERE rrid = 'RI' AND edate = 20050225
GROUP BY ardpfx, rinvc
UNION
SELECT ardpfx
|| rinvc rinvc,
SUM (rcamt) amt
FROM acrrar
WHERE rrid = 'RI' AND edate = 20050325
GROUP BY ardpfx, rinvc)
GROUP BY rinvc
HAVING SUM (amt) <>; 0)
AND edate IN (20050225, 20050325)
GROUP BY edate, ardpfx, rinvc
马上就可以跑出来,我不大了解,认为是Index的关系,于是加了个rrid(只是个标志位,仅有两个值)的索引,还是跑不出来,又加了个rrid,ardpfx,rinvc,edate的索引,还是跑不出来,我不知是什么原因,请各位高手赐教,万分感激! |
|