我有一个数据库表,其中的人由姓名、工作和城市标识。我有第二个表,其中包含每个城市公司中每个工作的分层表示。
假设我在 people 表中有 3 个人:
[name(PK),title,city]
Jim, Salesman, Houston
Jane, Associate Marketer, Chicago
Bill, Cashier, New York
我在工作表中有数千个工作类型/位置组合,下面是其中的一个示例。您可以看到层次关系,因为 parent_title 是标题的外键:
[title,city,pay,parent_title]
Salesman, Houston, $50000, CEO
Cashier, Houston, $25000
CEO, USA, $1000000
Associate Marketer, Chicago, $75000
Senior Marketer, Chicago, $125000
......
我遇到的问题是我的 Person 表是一个复合键,所以我不知道如何构造start with
我的查询部分,以便它从我指定的城市中的三个工作中的每一个开始。
我可以执行三个单独的查询来获得我想要的,但这不能很好地扩展。例如:
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
我怎么才能得到一个不同的列表(或者如果不可能的话,我可以用一个不同的列表来包装它)在我指定的三个人之上的所有工作?