Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:37:22+00:00 2026-05-26T16:37:22+00:00

[ Ed. Note: Related to this SO question ; didn’t edit question because the

  • 0

[Ed. Note: Related to this SO question; didn’t edit question because the problem has fundamentally shifted and question/answers from before are still valid]

Looking for advice of how best to create a view. The current query from my previous problem now works, but doesn’t account for the idea of parent/child items.

Relevant Data structure

+---------+      +---------+
|WORKORDER|      |WPLABOR  |
|---------|      |---------|
|WONUM    |+---->|WONUM    |
|PARENT   |  +   |LABORHRS |
|ISTASK   |  |   |RATE     |
|...      |  |   +---------+
|         |  |
+---------+  |   +---------+
             |   |WPITEM   |
             |   |---------|
             +-->|WONUM    |
             |   |ITEMQTY  |
             |   |UNITCOST |
             |   +---------+
             |
             |   +----------------+
             |   |LONGDESCRIPTION |
             |   |----------------|
             +-->|LDKEY           |
                 |LDTEXT          |
                 +----------------+

Goal

In layman’s terms, I am having someone enter a work order number, and pulling a report that has the work order’s information, plus a summary of labor and materials cost for all of the child workorders (also called task workorders)

Therefore, I need a view that returns:

  • The standard information about that workorder (ID’d by WONUM) — description, location, etc.
  • Total Labor Hours (SUM of LABORHRS) for each of its child task workorders
  • Total Labor cost (sum of LABORHRS*RATE) from WPLABOR For each of its child task workorders
  • Total Item Cost (SUM of ITEMQTY*UNITCOST) from WPITEM For each of its child task workorders

A Child Task Workorder is a workorder where parent = WONUM of first workorder and ISTASK=1

Use:

I would like to be able to call this in the following way:

SELECT * from [ViewName] where wonum = '123abc';

I know this involves a combination of subqueries and joins, I’m just not sure what the best way to structure the relationships, etc. is.

Current Query

SELECT WORKORDER.WONUM      ,
       WORKORDER.ACTLABHRS  ,
       WORKORDER.LOCATION   ,
       WORKORDER.STATUS     ,
       WORKORDER.WO7        , -- Requester
       WORKORDER.WO8        , -- Extension
       WORKORDER.WO9        , -- Location
       WORKORDER.LEADCRAFT  ,
       WORKORDER.WO11       , -- Extension
       WORKORDER.GLACCOUNT  ,
       WORKORDER.WO10       , -- Contact
       WORKORDER.DESCRIPTION, -- Short description
       WORKORDER.WO6        , -- Plant rearrangement (YORN / boolean value)
       WORKORDER.ISTASK     ,
       WORKORDER.PARENT     ,
       LABOR.TOTALLABORHRS  ,
       LABOR.LABORCOST      ,
       ITEM.ITEMCOST        ,
       DESCRIPTION.LDTEXT
FROM   MAXIMO.WORKORDER
       LEFT JOIN
              ( SELECT  WPLABOR.WONUM                                    ,
                       SUM(WPLABOR.LABORHRS * WPLABOR.RATE) AS LABORCOST ,
                       SUM(WPLABOR.LABORHRS)                AS TOTALLABORHRS
              FROM     MAXIMO.WPLABOR
              GROUP BY WONUM
              )
              LABOR
       ON     WORKORDER.WONUM = LABOR.WONUM
       LEFT JOIN
              ( SELECT  WPITEM.WONUM ,
                       SUM(WPITEM.ITEMQTY * WPITEM.UNITCOST) AS ITEMCOST
              FROM     MAXIMO.WPITEM
              GROUP BY WONUM
              )
              ITEM
       ON     WORKORDER.WONUM = ITEM.WONUM
       LEFT JOIN
              ( SELECT LONGDESCRIPTION.LDKEY,
                      LONGDESCRIPTION.LDTEXT
              FROM    MAXIMO.LONGDESCRIPTION
              WHERE   LONGDESCRIPTION.LDOWNERTABLE='WORKORDER'
              AND     LONGDESCRIPTION.LDOWNERCOL  = 'DESCRIPTION'
              )
              DESCRIPTION
       ON     WORKORDER.WONUM = CAST(DESCRIPTION.LDKEY AS VARCHAR(22)) HERE WORKORDER.ISTASK = 1;

Issues with Current Query

Because it doesn’t take child task workorders into account, it doesn’t return any labor or item records (none are directly associated with the parrent), and so the labor and item totals are always empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:37:23+00:00Added an answer on May 26, 2026 at 4:37 pm

    I’ve come up with a query that resolves the situation and is a little faster than “connect by prior “method (3 seconds compared to ~90 seconds).

    To make it a little easier, I separated the standard Work Order information into a separate view (I’d like to re-use it anyway).

    The query I ended up with (below) seems to do the trick:

    CREATE OR replace VIEW r_wo_costsummariesbyparent 
    AS 
      SELECT workorder.parent, 
             Nvl(SUM(wosummary.totallaborhoursforwo), 0) AS totallaborhoursforparent, 
             Nvl(SUM(wosummary.totallaborcostforwo), 0)  AS totallaborcostforparent, 
             Nvl(SUM(wosummary.totalitemcostforwo), 0)   AS totalitemcostforparent 
      FROM   maximo.workorder 
             inner join (SELECT workorder.wonum, 
                                Nvl(SUM(wplabor.laborhrs), 0) AS totallaborhoursforwo, 
                                Nvl(SUM(wplabor.laborhrs * wplabor.rate), 0) AS totallaborcostforwo, 
                                Nvl(SUM(wpitem.itemqty * wpitem.unitcost), 0) AS totalitemcostforwo 
                         FROM   maximo.workorder 
                                inner join maximo.wplabor 
                                  ON ( workorder.wonum = wplabor.wonum ) 
                                inner join maximo.wpitem 
                                  ON ( workorder.wonum = wpitem.wonum ) 
                         WHERE  workorder.istask = 1 
                         GROUP  BY workorder.wonum) wosummary 
               ON workorder.wonum = wosummary.wonum 
      GROUP  BY workorder.parent; 
    

    I use it in the following way:

    Select * from r_wo_costsummariesbyparent where parent = '123abc';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: This question is related to CodeIgniter-RestServer When I call model.save() from backbone the
Note: this is a different problem to https - it's related to privacy security
On a related note to this question , say I've got an file with
this is related to my last question ( NOTE: I already got some good
Note: It is related to this question . I am trying to create a
note: this question is related to PostGIS and Postgresql and is implemented with PHP
Note: This question IS programming related! It's all about better code and better software
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note : The code in this question is part of deSleeper if you want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.