zoukankan      html  css  js  c++  java
  • PLSQL分级取数据

    分级取数据

    select employee_id,last_name,job_id,manager_id from employees

    start with employee_id=101 --employee_id=101为父

    connect by prior employee_id=manager_id;--现在是由父指向子(从上到底)

    EMPLOYEE_ID LAST_NAME       JOB_ID  MANAGER_ID

    ----------- ------------------------- ---------- ----------

    101 Kochhar       AD_VP 100

    108 Greenberg       FI_MGR 101

    109 Faviet       FI_ACCOUNT 108

    110 Chen       FI_ACCOUNT 108

    111 Sciarra       FI_ACCOUNT 108

    112 Urman       FI_ACCOUNT 108

    113 Popp       FI_ACCOUNT 108

    200 Whalen       AD_ASST 101

    203 Mavris       HR_REP 101

    204 Baer       PR_REP 101

    205 Higgins       AC_MGR 101

    EMPLOYEE_ID LAST_NAME       JOB_ID  MANAGER_ID

    ----------- ------------------------- ---------- ----------

    206 Gietz       AC_ACCOUNT 205

    select employee_id,last_name,job_id,manager_id from employees

    start with employee_id=101 --employee_id=101为父

    connect by prior manager_id=employee_id;--现在是由子指向父(从底向上)

    EMPLOYEE_ID LAST_NAME       JOB_ID  MANAGER_ID

    ----------- ------------------------- ---------- ----------

    101 Kochhar       AD_VP 100

    100 King       AD_PRES

    select employee_id,last_name,job_id,manager_id from employees

    start with employee_id=101

    connect by prior employee_id=manager_id

    and employee_id!=108;

    EMPLOYEE_ID LAST_NAME       JOB_ID  MANAGER_ID

    ----------- ------------------------- ---------- ----------

    101 Kochhar       AD_VP 100

    200 Whalen       AD_ASST 101

    203 Mavris       HR_REP 101

    204 Baer       PR_REP 101

    205 Higgins       AC_MGR 101

    206 Gietz       AC_ACCOUNT 205

    select employee_id,last_name,job_id,manager_id from employees

    where employee_id!=108

    start with employee_id=101

    connect by prior employee_id=manager_id;

    EMPLOYEE_ID LAST_NAME       JOB_ID  MANAGER_ID

    ----------- ------------------------- ---------- ----------

    101 Kochhar       AD_VP 100

    109 Faviet       FI_ACCOUNT 108

    110 Chen       FI_ACCOUNT 108

    111 Sciarra       FI_ACCOUNT 108

    112 Urman       FI_ACCOUNT 108

    113 Popp       FI_ACCOUNT 108

    200 Whalen       AD_ASST 101

    203 Mavris       HR_REP 101

    204 Baer       PR_REP 101

    205 Higgins       AC_MGR 101

    206 Gietz       AC_ACCOUNT 205

    用LEVEL和LPAD格式化分级报告

    select lpad(last_name,length(last_name)+(LEVEL*2)-2,'$') as org_chart,level

    from employees

    start with employee_id=100

    connect by prior employee_id=manager_id;

  • 相关阅读:
    osx 编译安装配置 ruby on rails
    tls/ssl证书生成和格式转换
    nginx相关的一些记录
    用systemd脚本自动启动node js程序
    SSH Tunneling
    c代码读取目录信息
    用Qt Creator 对 leveldb 进行简单的读写
    centos 7 相关的一些记录
    发现一段精简的模板算法(非原创)
    几个常用的散列算法
  • 原文地址:https://www.cnblogs.com/kawashibara/p/9047661.html
Copyright © 2011-2022 走看看