我有一個數據庫表,由名稱,工作和城市標識的人員。我有第二個表格,其中包含每個城市公司中每個工作的分層表示。如何獲取分層查詢中的元素的清單列表?
假設我有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
我還能如何得到清晰的列表(或者我可以用一個不同的,如果不能把它包),所有這些都是我所指定的三人以上的工作?