Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2007, 12:44 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subquery as table

Hi all,

The followinf is sql I converted to run on oracle from sql server, not too sure about oracle so if anyone can show me how to do it right I'd be extremely greatful.

Thanks.


SELECT
         a.OEE,
         a.UnplannedDT,
         a.PlannedDT,
         (a.ScheduledDT + b.ScheduledDTTime) As "ScheduledDT",
         a.SpeedLossTime,
         a.YieldLossTime,
         a.AnalysisBy,
         a.Scheduled
FROM ( SELECT
             ROUND(SUM((PackedQty - wasteqty) / (OEERate / OEETimeUnit)), 2) AS OEE,
             SUM(UnplannedDT) As "UnplannedDT",
             SUM(PlannedDT) As "PlannedDT",
             SUM(breaks) As "ScheduledDT",
             ROUND(SUM((wasteqty) / (OEERate / OEETimeUnit)), 2) As "YieldLossTime",
             ROUND(SUM(runtime - ((PackedQty) / (OEERate / OEETimeUnit))), 2) As "SpeedLossTime",
             SUM(tblPO.TotalTime) As "Scheduled",
             Shift As "AnalysisBy"
    FROM tblPO,
         tblLines,
         tblProducts,
         staProdCategory,
         staArea,
         staFacilityLocation,
         staBusinessUnit,
         staPlant
    WHERE tblLines.Line = tblPO.Line
     AND (tblProducts.Product = tblPO.Product)
     AND (staProdCategory.ProdCatId = tblProducts.ProdCatId)
     AND (staArea.AreaID = tblLines.AreaID)
     AND (staFacilityLocation.FacilityID = staArea.FacilityID)
     AND (staBusinessUnit.UnitID = staFacilityLocation.UnitID)
     AND (staPlant.PlantID = staBusinessUnit.PlantID)
     AND (tblLines.AnalysisType = 'OEE'
     AND OEERATE > 0
     AND OEETIMEUNIT > 0
     AND tblLines.Line IN ( 'LTHE0016' )
     AND date_ >= '01-Nov-06'
     AND date_ < '08-Nov-06')
    GROUP BY Shift
) a,
    ( SELECT
             SUM(ScheduledDTHours * 60) AS ScheduledDTTime,
             SUM((DECODE(1 , DECODE( 2 ,DECODE( StartTime , NULL , 1 , 0 ) + DECODE( FinishTime , NULL , 1 , 0 ) , 1 , 0 ) ,ScheduledHours * 60,ROUND(( (DECODE(1 , DECODE( 1 ,DECODE(ABS(FinishTime - (SYSDATE) ),0,0, (FinishTime - (SYSDATE) ),1,0 ) , 1 , 0 ) ,(SYSDATE),FinishTime)) - StartTime ) *24*60)) + addtnscheduledhours * 60) - unscheduledhours * 60) AS scheduled,
             Shift As "AnalysisBy"
    FROM staworkpatterns,
         tblLines,
         staArea,
         staFacilityLocation,
         staBusinessUnit,
         staPlant
    WHERE tblLines.Line = staworkpatterns.WorkCentreID
     AND (staArea.AreaID = tblLines.AreaID)
     AND (staFacilityLocation.FacilityID = staArea.FacilityID)
     AND (staBusinessUnit.UnitID = staFacilityLocation.UnitID)
     AND (staPlant.PlantID = staBusinessUnit.PlantID)
     AND (tblLines.AnalysisType = 'OEE'
     AND staworkpatterns.workcentreid IN ( 'LTHE0016' )
     AND staworkpatterns.currentdate >= '01-Nov-06'
     AND staworkpatterns.currentdate < '08-Nov-06')
    GROUP BY Shift
) b
WHERE a.AnalysisBy = b.AnalysisBy
ORDER BY a.Scheduled DESC

  #2 (permalink)  
Old January 22nd, 2007, 02:10 PM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

brettk_1:
More information is needed, because what you have written would not execute successfully in Oracle. It is difficult to believe that the code you submitted executed successfully in SQL Server. The following information is needed in order to answer your question: What do you mean by in your topic- Subquery as table; sample of what the output should be; schemas of db tables, used in the query.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subquery debbiecoates SQL Server 2000 4 June 25th, 2008 03:49 AM
Do i have to use a subquery, if yes then how? code_lover SQL Language 2 January 2nd, 2007 02:22 PM
help with mysql subquery pnj MySQL 1 October 24th, 2006 05:42 PM
Help...subquery problem Twistdmojo Classic ASP Databases 4 September 14th, 2006 11:45 AM
subquery khansa MySQL 1 February 21st, 2006 02:49 AM



All times are GMT -4. The time now is 09:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.