我有一个数据库表,由名称,工作和城市标识的人员。我有第二个表格,其中包含每个城市公司中每个工作的分层表示。如何获取分层查询中的元素的清单列表?
假设我有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
.....
我遇到的问题是,我一个人表是一个复合键,所以我不我不知道如何构建我的查询的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
我还能如何得到清晰的列表(或者我可以用一个不同的,如果不能把它包),所有这些都是我所指定的三人以上的工作?