can we write below query in a better way [message #433758] |
Fri, 04 December 2009 02:11 |
chaituu
Messages: 115 Registered: June 2008
|
Senior Member |
|
|
can we write below query in a better way because its taking lot of time to execute?
SELECT COUNT(*)
FROM INVOICE INV
WHERE INV.STATUS_CODE = 'POST'
AND INV.TYPE_CODE IN ('INVOICED', 'NON_INVOICED')
AND EXISTS
(SELECT 'x'
FROM CHARGE jc
WHERE JC.INVOICE_ID = INV.INVOICE_ID
AND JC.STATUS <> 'CLOSED'
UNION ALL
SELECT 'x' FROM CHARGE_TAX TAX WHERE TAX.INVOICE_ID = INV.INVOICE_ID)
AND ABS(INV.GROSS_AMT -
(NVL((SELECT SUM(NVL(JC.NET_AMOUNT, 0))
FROM CHARGE jc
WHERE JC.INVOICE_ID = INV.INVOICE_ID
AND JC.STATUS <> 'CLOSED'),
0) + NVL((SELECT SUM(NVL(TAX.NET_AMOUNT, 0))
FROM CHARGE_TAX TAX
WHERE TAX.INVOICE_ID = INV.INVOICE_ID),
0))) > 0.1;
|
|
|
|
|
|
Re: can we write below query in a better way [message #433780 is a reply to message #433764] |
Fri, 04 December 2009 04:31 |
Its_me_ved
Messages: 979 Registered: October 2009 Location: India
|
Senior Member |
|
|
Quote:
I have a big car! I can park it on left/ right side of the road.
Please advice how can i make it run fast Just kidding.
Just to tell you that the information you have provided is still not sufficient.Could you provide test case( create table insert stament (with some test data)) and your expected output?
[Updated on: Fri, 04 December 2009 04:44] Report message to a moderator
|
|
|
Re: can we write below query in a better way [message #433783 is a reply to message #433780] |
Fri, 04 December 2009 04:52 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
This is a query tuning question - a test case isn't what we need here.
What we need is the sort of information detailed in the Sticky Post at the top of the Performance Tuning forum.
To make it easier to find, that's where this post now is.
|
|
|
|
|
|
|
|