Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

How to join 2 tables and traverse up hierarchy at the same time

$
0
0

Any help that can be given on a current problem I’m having in an Oracle environment would be greatly appreciated.

I have 2 tables. One contains jobs to be performed on pieces of equipment, the other contains the equipment hierarchy which is expressed as equip_no/parent_equip_no. This second table also contains other information such as equip_class which is of interest here.

Given a batch of jobs selected by date range I’ve been asked to then group these jobs by their equipment bay. Each item in the equipment hierarchy has a class. The equipment bay can be determined by finding the entry for the equip_no associated with the job and crawling up the equipment hierarchy until you hit an item which has it’s equipment class tagged as being an equipment bay (eb). This crawling could be through any number of layers.

So here’s some table structures

table A (jobs table)
--------------------
equip_no
job_num

table B (equipment hierarchy)
-----------------------------
equip_no
parent_equip_no
equip_name
equip_class

I’d like to produce the following table

table C
-------
A.equip_no
A.job_no
B.equip_name of upstream hierarchy entry where equip_class = 'eb'

Any help is appreciated.


Viewing all articles
Browse latest Browse all 717

Trending Articles