首页 > 其他分享 >28.层次查询

28.层次查询

时间:2023-02-26 20:58:28浏览次数:44  
标签:__ ______ 层次 King 28 查询 ____ id name

遍历树自底到顶

hr@ORCLPDB01 2023-02-26 20:31:01> select employee_id,last_name,job_id,manager_id
  2  from employees
  3  start with employee_id = 101
  4  connect by prior manager_id = employee_id;

EMPLOYEE_ID LAST_NAME		      JOB_ID	 MANAGER_ID
----------- ------------------------- ---------- ----------
	101 Kochhar		      AD_VP		100
	100 King		      AD_PRES

Elapsed: 00:00:00.01

遍历树自顶到底

hr@ORCLPDB01 2023-02-26 20:34:35> select last_name||' reports to '||
  2  prior last_name "Walk top Down"
  3  from employees
  4  start with last_name = 'King'
  5  connect by prior employee_id = manager_id;

Walk top Down
--------------------------------------------------------------
King reports to
King reports to
Kochhar reports to King
Greenberg reports to Kochhar
Faviet reports to Greenberg
Chen reports to Greenberg

使用level和lpad美化层次报告

hr@ORCLPDB01 2023-02-26 20:40:40> r
  1  select lpad(last_name,length(last_name)+(level*2)-2,'_')
  2  as org_chart
  3  from employees
  4  start with first_name = 'Steven' and last_name = 'King'
  5* connect by prior employee_id = manager_id

ORG_CHART
--------------------
King
__Kochhar
____Greenberg
______Faviet
______Chen
______Sciarra
______Urman
______Popp
____Whalen
____Mavris
____Baer
____Higgins
______Gietz
__De Haan
____Hunold
______Ernst
______Austin
______Pataballa
______Lorentz
__Raphaely
____Khoo
____Baida
____Tobias
____Himuro
____Colmenares
__Weiss
____Nayer
____Mikkilineni
____Landry
____Markle
____Taylor
____Fleaur
____Sullivan
____Geoni
__Fripp
____Bissot
____Atkinson
____Marlow
____Olson
____Sarchand
____Bull
____Dellinger
____Cabrio
__Kaufling
____Mallin
____Rogers
____Gee
____Philtanker
____Chung
____Dilly
____Gates
____Perkins
__Vollman
____Ladwig
____Stiles
____Seo
____Patel
____Bell
____Everett
____McCain
____Jones
__Mourgos
____Rajs
____Davies
____Matos
____Vargas
____Walsh
____Feeney
____OConnell
____Grant
__Russell
____Tucker
____Bernstein
____Hall
____Olsen
____Cambrault
____Tuvault
__Partners
____King
____Sully
____McEwen
____Smith
____Doran
____Sewall
__Errazuriz
____Vishney
____Greene
____Marvins
____Lee
____Ande
____Banda
__Cambrault
____Ozer
____Bloom
____Fox
____Smith
____Bates
____Kumar
__Zlotkey
____Abel
____Hutton
____Taylor
____Livingston
____Grant
____Johnson
__Hartstein
____Fay

 

标签:__,______,层次,King,28,查询,____,id,name
From: https://www.cnblogs.com/yuanzijian/p/17157614.html

相关文章

  • 25.高级子查询
    1.多列子查询--主查询中每条记录都会与多条记录和多字段子查询得结果进行比较--列对比匹配原则----多字段子查询得字段比较有两种------成对比较hr@ORCLPDB012023-02......
  • (AtCoder Beginner Contest 289)And Codeforces Round #851 (Div. 2)
     <C-Coverage Editorial>       这道题可以用dfs进行爆搜,但是在爆搜的时候要注意:是否同一个状态重复计数了比如dfs(i......
  • 4.1- 存储系统层次结构
    基本存储体系原理:包括:存储程序(存储设备),程序控制(CPU)1.输入输出设备将程序与数据写入主存2.CPU取指令3.CPU执行指令期间读取数据4.CPU写回运算结果5.输出设备输出......
  • Mysql中关于查询日志的配置详解
    查询日志MySQL中的查询日志保存在文本文件中,能够记录MySQL中的所有数据操作。开启查询日志MySQL默认情况下没有开启查询日志,如果需要开启查询日志,则需要在​​my.cnf​​​......
  • limit offset慢查询学习
    转自:https://cloud.tencent.com/developer/article/19622761.用法 1.select*fromarticleLIMIT1,32.select*fromarticleLIMIT3OFFSET1均表示略过第一条......
  • AtCoder Beginner Contest 281 A-F 题解
    比赛链接A-CountDown先这样,就这样。点击查看代码#include<cstdio>intn;intmain(){ scanf("%d",&n); for(inti=n;i>=0;i--)printf("%d\n",i); re......
  • 《黑马旅游网》综合案例九 旅游线路查询
    参数传递header.html:(注入导入js/getParameter.js文件)<!--头部start--><scriptsrc="js/getParameter.js"></script><script>//给搜索按钮绑定单击事件,获取搜索输入......
  • ssm学习笔记23001-mybatis基础查询
    myBatis的基础查询单条或多条查询根据id查询单条数据,查询所有数据的列表集合,查询所有数据的条目,查询出单条数据返回值为map,查询多条数据返回值为列表,查询多条数据返回值......
  • MongoDB在银行海量历史订单交易数据查询中的应用(Spring boot + Bee)
    MongoDB在银行海量历史订单交易数据查询中的应用(Springboot+Bee)近年来,随着各种便捷支付方式的普及,银行账户交易数据呈现爆炸式增长,同时数据模型也在不断变化,传统关......
  • Iceberg 数据治理及查询加速实践
    数据治理Flink实时写入Iceberg带来的问题在实时数据源源不断经过Flink写入的Iceberg的过程中,Flink通过定时的Checkpoint提交snapshotcommit操作到Iceberg,......