分层查询

时间:2015-03-11 15:09:11

标签: sql oracle

当我选择主管时,我需要得到所有下属。我从前端传递employee_id然后它必须获取所有人都在他/她之下的数据。

我在下面有对齐和员工的表格结构。

表格: 对齐:

ALIGNMENT_ID    NOT NULL    NUMBER(16)
TEAM_ID NOT NULL    NUMBER(16)
EMPLOYEE_ID     NUMBER(16)
ALIGNMENT_NAME  NOT NULL    VARCHAR2(200)
EXTERNAL_ID_1       VARCHAR2(200)
STATUS  NOT NULL    VARCHAR2(4)
STATUS_CHANGE_DATE  NOT NULL    DATE
MANAGER_ALIGNMENT_ID        NUMBER(16)
TEAM_ADMINISTRATOR      VARCHAR2(4)
REPORT_LEVEL        VARCHAR2(4)
ROLE        VARCHAR2(4)
POD_ALIGNMENT_ID        NUMBER(16)

员工:

EMPLOYEE_ID NOT NULL    NUMBER(16)
EXTERNAL_ID_1       VARCHAR2(200)
EXTERNAL_ID_2       VARCHAR2(200)
JOB_PROFILE_TYPE        VARCHAR2(4)
FIRST_NAME  NOT NULL    VARCHAR2(200)
MIDDLE_NAME     VARCHAR2(200)
LAST_NAME   NOT NULL    VARCHAR2(200)
SECOND_LAST_NAME        VARCHAR2(200)
DISPLAY_NAME        VARCHAR2(200)
BIRTH_DATE      DATE
STATUS  NOT NULL    VARCHAR2(4)
STATUS_CHANGE_DATE  NOT NULL    DATE
STATUS_REASON       VARCHAR2(4)
SAMPLING_STATUS     VARCHAR2(4)
MACHINE_NODE_ID     NUMBER(9)
LOGIN_ID        VARCHAR2(200)
TITLE       VARCHAR2(4)

对齐数据:

17432000000411  7888500000120271    17432000000427  india_ho    india_ho    ACTV    28-06-2013 06:44:53         0   VPOS
1006387676  7888500000120271    1006381821  EST REGION  EST REGION  ACTV    28-05-2013 15:41:56 17432000001417          RM
1006387677  7888500000120271    60000001963869  E-AREA1 E-AREA1 ACTV    28-05-2013 15:41:56 1006387676          DM
1006387678  7888500000120271    60000001963939  E-AREA2 E-AREA2 ACTV    28-05-2013 15:41:56 1006387676          DM
1006387679  7888500000120271    60000001963930  E-AREA3 E-AREA3 ACTV    28-05-2013 15:41:56 1006387676          DM
1006387680  7888500000120271    60000001963946  E-AREA4 E-AREA4 ACTV    28-05-2013 15:41:56 1006387676          DM
1006387681  7888500000120271    60000001963733  E-AREA6 E-AREA6 ACTV    28-05-2013 15:41:56 1006387676          DM
1006387682  1000000338771   60000001963734  E-AS-GUW-A07    E-AS-GUW-A07    ACTV    28-05-2013 16:17:30 1006387680          REP
1006387683  1000000338771   60000001963711  E-AS-GUW-A08    E-AS-GUW-A08    ACTV    28-05-2013 16:17:30 1006387680          REP
1006387684  1000000338772   60000001963729  E-AS-GUW-B07    E-AS-GUW-B07    ACTV    28-05-2013 16:17:30 1006387680          REP
1006387685  1000000338772   60000001963786  E-AS-GUW-B08    E-AS-GUW-B08    ACTV    28-05-2013 16:17:30 1006387680          REP
1006387686  1000000338771   18910000251233  E-CT-RAIP-A11   E-CT-RAIP-A11   ACTV    28-05-2013 16:17:30 1006387679          REP
1006387687  1000000338772   18910000194383  E-CT-RAIP-B11   E-CT-RAIP-B11   ACTV    28-05-2013 16:17:30 1006387679          REP
1006387688  1000000338771       E-MP-JABA-A09   E-MP-JABA-A09   INAC    19-01-2015 11:31:33 1006387681          REP
1006387689  1000000338773   60000001963891  E-MP-JABA-B09   E-MP-JABA-B09   ACTV    28-05-2013 16:17:30 1006034504          REP
1006387690  1000000338771   60000001963805  E-OR-BHUB-A05   E-OR-BHUB-A05   ACTV    28-05-2013 16:17:30 1006387678          REP
1006387691  1000000338772   60000001963873  E-OR-BHUB-B05   E-OR-BHUB-B05   ACTV    28-05-2013 16:17:30 1006387678          REP

在对齐表中我们有 喜欢VPOS' - 1,' RM' - 2,' DM' - 3,' REP' - 4。我从上到下给了订单。 VPOS是主管人员(主管)。

如果我选择VPOS,那么所有数据都必须从查询中获取。如果我选择RM,则必须显示DM和REP,如果我选择DM,则必须显示REP。

1 个答案:

答案 0 :(得分:0)

这是结构查询,您可以将其与员工查询一起加入

select * from alignment
start with employee_id = %your_input_id%
connect by manager_alignment_id = prior alignment_id