日期:2014-05-17  浏览次数:20950 次

优化一个SQL语句200分
优化这个SQL语句
select   a.post_code,   a.inst_code,   a.post_name,   to_char(b.change_date,   'YYYY-MM-DD ')   as   change_date
    from   t_hr_b_post   b,   t_mgt_post   a
  where   confirmflag   =   '00590002 '   and   a.post_code   =   b.post_code   and  
      exists(select   1
                        from   (select   max(emp_post_id)   as   emp_post_id
                                        from   t_hr_b_post   a
                                      where   confirmflag   =   '00590002 '   and
                                          exists(select   1
                                                            from   (select   emp_id,   min(nvl(post_on_type,   '0068002 '))   post_on_type
                                                                            from   t_hr_b_post
                                                                          where   confirmflag   =   '00590002 '
                                                                        group   by   emp_id
                                                                      )b
                                                          where   a.emp_id   =   b.emp_id   and   nvl(a.post_on_type,   '0068002 ')   =   b.post_on_type
                                                      )
                                  group   by   emp_id
                                )   c  
                    where