晒晒我的sql语句,请求指点

select t5.v01000,
       (select avg(seq)
          from (select t.*,
                       to_char(to_char(t.event_date, 'DDD'), '999') as seq
                  from T_LTCD_FROSTY_HIST t) t8
         where t8.v01000 = t5.v01000
         group by t8.v01000),
       t5.v04002 || '-' || t5.v04003,
       t6.v04002 || '-' || t6.v04003,
       (select avg(seq) -
               (select avg(seq)
                  from (select t.*,
                               to_char(to_char(t.event_date, 'DDD'), '999') as seq
                          from T_LTCD_FROSTY_HIST t) t8
                 where t8.v01000 = t7.v01000
                 group by t8.v01000)
          from (select t.*,
                       to_char(to_char(t.event_date, 'DDD'), '999') as seq
                  from T_LTCD_FROSTY_HIST t) t7
         where t7.v01000 = t5.v01000
         group by t7.v01000)
  from (select distinct t2.v01000 as v01000, t2.v04002, t2.v04003
          from (select t.*,
                       to_char(to_char(t.event_date, 'DDD'), '999') as seq
                  from T_LTCD_FROSTY_HIST t) t2
         where t2.seq in
               (select max(t1.seq)
                  from (select t.*,
                               to_char(to_char(t.event_date, 'DDD'), '999') as seq
                          from T_LTCD_FROSTY_HIST t) t1
                 group by t1.v01000)) t5
  left join (select distinct t3.v01000 as v01000, t3.v04002, t3.v04003
               from (select t.*,
                            to_char(to_char(t.event_date, 'DDD'), '999') as seq
                       from T_LTCD_FROSTY_HIST t) t3
              where t3.seq in
                    (select min(t4.seq)
                       from (select t.*,
                                    to_char(to_char(t.event_date, 'DDD'),
                                            '999') as seq
                               from T_LTCD_FROSTY_HIST t) t4
                      group by t4.v01000)) t6
    on t5.v01000 = t6.v01000

posted @ 2012-08-07 18:28  人间烟火  阅读(223)  评论(0)    收藏  举报