有两张结构完全相同的表,都有大量的数据。现在想通过一条SQL同时查询两张表,因此使用了union(all),例如:
select * from t1
where endtime >= to_Date('2007-04-01',' yyyy-mm-dd')
union all
select *
from t2
where endtime >= to_Date('2007-04-01',' yyyy-mm-dd')
当发现此条SQL语句的执行时间很长。
问题1:是否有办法优化?
另外:还有带统计的查询SQL,如:
select avg(consume),sum(consume),max(consume),min(consume),count(*)
from t3
where endtime >= to_Date('2007-04-01',' yyyy-mm-dd')
group by trunc(endtime,'dd')
order by trunc(endtime,'dd') desc
问题2: 如果同样要查询统计两个表的数据结果,该如何实现?
谢谢!