Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Oracle / Oracle Server / September 2005

Tip: Looking for answers? Try searching our database.

How can I re-write this piece of code for better performance!?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lou_nyc - 30 Sep 2005 20:41 GMT
select  p.d_insp_date,
       p.d_dam_date_by
      ,b.stat
      ,NVL(a.cnt,0) CNT
from
    (select aa.dam_insp_date,
            a.dam_insp_by,
            bb.stat
       from (select distinct trunc(gc.dam_insp_date) gc.dam_insp_date,
gc.dam_insp_by
               from damages gd, gate_con gc
              where gd.g_id = gc.g_id
            ) aa,
            (select *
               from (select 'MAJOR' STATUS from dual
                     union all
                     select 'MINOR' STATUS from dual
                     union all
                     select 'TOTAL' STATUS from dual
                    )
            ) bb
    )b,
    ((SELECT  dam_insp_date,
              dam_insp_by,
              Stat,
              cnt
         FROM (select trunc(c.dam_insp_date) dam_insp_date,
                      c.dam_insp_by,
                      'MAJOR' STATUS,
                      count(distinct c.g_id) cnt
                 from gate_cont c,
                      damages d
                where c.gate_id = d.gate_id and
                      d.damage_type_code = 'A'
             group by
trunc(c.damage_inspection_date),c.damage_inspection_by
               UNION ALL
              select trunc(g.damage_inspection_date)
damage_inspection_date,
                      g.damage_inspection_by,
                      'MINOR' STATUS,
                      count(distinct g.gate_id) cnt
                 from gate_containers g,
                      damages z
                where g.gate_id = z.gate_id and
                      z.damage_type_code = 'F'
             group by
trunc(g.damage_inspection_date),g.damage_inspection_by
              UNION ALL
               select  trunc(ap.d_insp_date) damage_inspection_date,
                       ap.d_dam_date_by,
                      'TOTAL' STATUS,
                      count(distinct ab.gate_id) cnt
                 from gate_containers ab,
                      damages ac
                where ab.gate_id = ac.gate_id
             group by trunc(ap.d_insp_date),ap.d_dam_date_by
                   )
              group by damage_inspection_date, damage_inspection_by,
status, cnt
              )
    ) a
where p.d_dam_date_by = a.damage_inspection_by(+)
 and p.d_insp_date = a.damage_inspection_date(+)
 and b.status = a.status(+);
lou_nyc - 30 Sep 2005 21:01 GMT
Please disregard this post... please look at the newer one!
lou_nyc - 30 Sep 2005 21:06 GMT
this is the most updated post..
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.