I need help to make a query to be optimized. And suggest if there is any other way to accomplish the same by using any other query.
WITH
q1 as
(select eid, data_used||'-'||status as value1
from T1 inner join T2 ON (t1.eid = t2.eid)
where <conditions>),
q2 as
(select eid, data_used||'-'||status as value2
from T1 inner join T2 ON (t1.eid = t2.eid)
where <conditions different from q1 >),
q3 as
(select eid, data_used||'-'||status as value3
from T1 inner join T2 ON (t1.eid = t2.eid)
where <conditions different from q2>)
select q1.eid, q1.value1, q2.value2, q3.value3
from q1, q2, q3
where q1.eid = q2.eid
and q2.eid=q3.eid;
The query will give output as follows:
I meant to say value1, value 2, value 3 can be different for a same eid according to the conditions in q1, q2 and q3.
Both tables T1 and T2 are audit tables hence eid repeats multiple times in both.
I'm really tired of optimizing and making this query shorter. I'm new to this. Hence I would like to know if there is any other way to get it done. I have created indexes on these tables and yet it is returning the data in 77 seconds. I need to reduce the time at least by 10 - 15 seconds. Current data volume is 100k records and it is going to grow as billions.