我的需求是从每天的日志表内获取目前有哪些strapp_type1(一级类别), strapp_type2(二级类别)的分类,看我的sql:select min(rownum) id,strapp_type1,strapp_type2 from (
select min(rownum) id,strapp_type1,strapp_type2 from log_dpitran_20120608 t group by strapp_type1,strapp_type2
union 
select min(rownum) id,strapp_type1,strapp_type2 from log_dpitran_20120609 t group by strapp_type1,strapp_type2
union 
select min(rownum) id,strapp_type1,strapp_type2 from log_dpitran_20120610 t group by strapp_type1,strapp_type2) a 
group by strapp_type1,strapp_type2 order by strapp_type1;
现在我数据库是保留一个月的日志表,这样如果用union来查询这30张表的话,速度就很慢,耗费大量时间,想问这sql如何优化,或者其他方式来达到要求,请高手给个sql语句,万分感谢!!!

解决方案 »

  1.   

    查询语句的结果是这样的:strapp_type1           strapp_type2
    DNS              DNS协议
    DNS              mDNS协议
    FTP              ftp上传
    FTP              ftp下载
    FTP              ftp命令
    ......
      

  2.   

    能给个具体的sql参考吗?  感谢
      

  3.   

    能给个具体的sql参考吗?  感谢
      

  4.   

    用union all 加 distinct 试试? 别分组
    select distinct strapp_type1,strapp_type2 from (
    select distinct strapp_type1,strapp_type2 from log_dpitran_20120608 t union all
    select distinct strapp_type1,strapp_type2 from log_dpitran_20120609 t union all 
    select disctint strapp_type1,strapp_type2 from log_dpitran_20120610 t ) a