How can I get a separate list of items in a hierarchical query?

I have a database table with people identified by name, assignment and city. I have a second table that contains a hierarchical view of each work in the company in each city.

Suppose I have 3 people in a people table:

[name(PK),title,city]
Jim, Salesman, Houston
Jane, Associate Marketer, Chicago
Bill, Cashier, New York

And I have thousands of work / location type combinations in the assignment table, examples of which follow. You can see the hierarchical relationship as parent_title is the foreign key to the header:

[title,city,pay,parent_title]
Salesman, Houston, $50000, CEO
Cashier, Houston, $25000
CEO, USA, $1000000
Associate Marketer, Chicago, $75000
Senior Marketer, Chicago, $125000

.....

The problem that I encountered is that my Person table is a composite key, so I don’t know how to structure part of start withmy query so that it starts with each of the three tasks in the cities I specified.

, , , . :.

select * from jobs
start with city = (select city from people where name = 'Bill') and title = (select title from people where name = 'Bill')
connect by prior parent_title = title
UNION
select * from jobs
start with city = (select city from people where name = 'Jim') and title = (select title from people where name = 'Jim')
connect by prior parent_title = title
UNION
select * from jobs
start with city = (select city from people where name = 'Jane') and title = (select title from people where name = 'Jane')
connect by prior parent_title = title

( , ) , ?

+3
2

. .

SELECT  distinct *
FROM    jobs
START   WITH ( city, title ) IN 
     ( SELECT city, title
       FROM   people
       WHERE  name IN ( 'Bill', 'Jim', 'Jane' )
     )
CONNECT BY PRIOR parent_title = title;
+2

:

SQL> SELECT *
  2    FROM jobs
  3   START WITH (title, city) IN (SELECT title, city FROM people)
  4  CONNECT BY PRIOR parent_title = title;

TITLE              CITY           PAY PARENT_TITLE
------------------ ------- ---------- ------------
Associate Marketer Chicago       7500 
Salesman           Houston       5000 CEO
CEO                USA         100000 
+1

Source: https://habr.com/ru/post/1746314/


All Articles