Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> SQL -- minimizing table access
I have a original query conceptually like this:
select 1,
sum(C1)
from tableA
where C2 < 0
union
select 2,
sum(C1)
from tableA
where C2 > 0
Since this is a union query, it makes table access to tableA for 2 times,
which in fact a single access
of tableA should be enough, so I rewrite the query to something like this:
select
sum(case when temp.C2 > 0 then C2 else 0 end) column_1, sum(case when temp.C2 < 0 then C2 else 0 end) column_2 from (select C2 from tableA) temp
after the rewrite, I found it to be faster, requiring only half of logical
read which is my expectation.
But the problem is that the original display like this:
1 100 2 200
becomes like this:
100 200
? how can I turn the display back to its original form with minimal effort??
Thx a lot Received on Tue May 13 2003 - 08:27:14 CDT