'How to return work order in one particular status and all associated work orders against that asset only?

Hi I have a query to return all open work orders with the following work types (PM, PJ, RD). How do I:

  1. Return only PM work orders in WSCH status
  2. And if those assets are PMs in WSCH status, then return all open work types (PMs, PJs, RDs) against those assets exclusively.

Any tips for how I would handle this query would be great.

3/3/2022: Edit to include current output and desired output: Edit for Current output and desired output

Sample Query to return all open work orders:

SELECT
WO.Asset,
WO.Description,
WO.Status,
WO.Wonum,
WO.Worktype
FROM
Maximo.Workorder WO
WHERE
--Historyflag =0 will bring in all Statuses except Close, (ie COMP, Cancel, WSCH, Inprg, IHP, LO, PH etc)
WO.Historyflag =0 AND
WO.Worktype IN ('PM', 'PJ','RD')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source