2012-07-29 171 views
1
SELECT ppse.SUBORDINATE_POSITION_ID child_position_id 
       ,ppse.PARENT_POSITION_ID manger_position_id 
       ,b.person_id 
FROM per_pos_structure_elements_v ppse 
     ,APPS.xxkpc_hr_personnel_v2_mv b 
WHERE b.position_id(+) = ppse.SUBORDINATE_POSITION_ID 

AND ppse.POS_STRUCTURE_VERSION_ID =64 
AND ppse.PARENT_POSITION_ID=12493 

輸出此查詢:SQL層次查詢

12604 12493 400 
12605 12493 108 
13644 12493 37897 
12752 12493 18 
13643 12493  
13642 12493  
13641 12493  



SELECT ppse.SUBORDINATE_POSITION_ID child_position_id 
       ,ppse.PARENT_POSITION_ID manger_position_id 
       ,b.person_id 
FROM per_pos_structure_elements_v ppse 
       ,APPS.xxkpc_hr_personnel_v2_mv b 
WHERE b.position_id(+) = ppse.SUBORDINATE_POSITION_ID 

AND ppse.POS_STRUCTURE_VERSION_ID =64 
AND ppse.PARENT_POSITION_ID=12504 


12514 12504 449 
12483 12504 450 
12487 12504 456 
12497 12504 156 
12889 12504 168 
12493 12504 

12493是第一個查詢父母是孩子的第2個查詢,所以我需要刪除具有空爲person_id(第三列)中的所有行&沒有父對於孩子的在第二查詢堂妹,他是孩子的在第一個查詢,但在第一次查詢

+0

@marc_s Oracle DB 11g – 2012-07-29 08:05:49

回答

0

嘗試這樣的事情,除去最後3行父我不能刪除最後一排...

SELECT ppse.SUBORDINATE_POSITION_ID child_position_id 
      ,ppse.PARENT_POSITION_ID manger_position_id 
      ,b.person_id 
FROM per_pos_structure_elements_v ppse 
    ,APPS.xxkpc_hr_personnel_v2_mv b 
WHERE b.position_id(+) = ppse.SUBORDINATE_POSITION_ID 
AND b.type(+) = 'KPC Employee' 
AND ppse.POS_STRUCTURE_VERSION_ID =64 
AND ppse.PARENT_POSITION_ID=12493 
AND 
(b.person_id!=null OR 
ppse.SUBORDINATE_POSITION_ID in 
      (SELECT SUBORDINATE_POSITION_ID from per_pos_structure_elements_v)) 
+0

它不與PARENT_POSITION_ID = 12504一起使用,它將刪除12493的行,該行是子級的父級 – 2012-07-29 08:29:36

+0

嘗試從最後一條語句中刪除NOT。顯示如下... ppse.SUBORDINATE_POSITION_ID in (從per_pos_structure_elements_v中選擇SUBORDINATE_POSITION_ID)) – 2012-07-29 08:37:02