資料庫開發基礎--層次查詢+
with bus as
(select 'A' dstart, 'B' dend, '120' distance
from dual
union all
select 'B' dstart, 'C' dend, '200' distance
from dual
union all
select 'A' dstart, 'D' dend, '150' distance
from dual
union all
select 'D' dstart, 'M' dend, '300' distance
from dual
union all
select 'C' dstart, 'E' dend, '180' distance
from dual
union all
select 'F' dstart, 'M' dend, '260' distance from dual)
select level,
connect_by_root dstart,
dend,
distance,
SYS_CONNECT_BY_PATH(dstart, '->'),
SYS_CONNECT_BY_PATH(dstart, '->') || '->' || dend,
lead(distance,level-1)over(partition by level order by level)
from bus
start with dstart is not null
connect by (prior dend = dstart);
-----------------------------------------------
with bus as
(
select 'A' dstart, 'B' dend, '120' distance from dual union all
select 'B' dstart, 'C' dend, '200' distance from dual union all
select 'A' dstart, 'D' dend, '150' distance from dual union all
select 'D' dstart, 'M' dend, '300' distance from dual union all
select 'C' dstart, 'E' dend, '180' distance from dual union all
select 'F' dstart, 'M' dend, '260' distance from dual
)
select * from bus;
------------------------------------------
with bus as
(
select 'A' dstart, 'B' dend, '120' distance from dual union all
select 'B' dstart, 'C' dend, '200' distance from dual union all
select 'A' dstart, 'D' dend, '150' distance from dual union all
select 'D' dstart, 'M' dend, '300' distance from dual union all
select 'C' dstart, 'E' dend, '180' distance from dual union all
select 'F' dstart, 'M' dend, '260' distance from dual
)
select dstart, wmsys.wm_concat(dend) from bus group by dstart
--------------------------
with bus as
(
select 'A' dstart, 'B' dend, '120' distance from dual union all
select 'B' dstart, 'C' dend, '200' distance from dual union all
select 'A' dstart, 'D' dend, '150' distance from dual union all
select 'D' dstart, 'M' dend, '300' distance from dual union all
select 'C' dstart, 'E' dend, '180' distance from dual union all
select 'F' dstart, 'M' dend, '260' distance from dual
)
select dstart,dend, CONNECT_BY_ISLEAF isleaf,
sys_connect_by_path(dstart, '->')||'-'||dend "Path"
FROM bus
START WITH dstart IS NOT NULL
CONNECT BY PRIOR dend =dstart;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30018455/viewspace-1470492/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料庫開發基礎---層次查詢資料庫
- 資料庫基礎查詢--單表查詢資料庫
- MySQL資料庫基礎——多表查詢:子查詢MySql資料庫
- 【--SQL基礎-->層次化查詢(START BY ... CONNECT BY PRIOR)】SQL
- 資料庫——基礎(資料庫操作,表格操作)——增加高階查詢資料庫
- 《資料庫》基礎題一:兩表相關查詢資料庫
- php基礎之連線mysql資料庫和查詢資料PHPMySql資料庫
- CDA資料分析師 - SQL資料庫基礎 查詢&連線SQL資料庫
- Oracle層次化查詢Oracle
- java 查詢資料庫並生成多層childrenJava資料庫
- 資料庫開發基礎---行列轉換資料庫
- 0629_層次查詢
- AndoridSQLite資料庫開發基礎教程(10)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(9)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(8)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(7)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(6)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(5)SQLite資料庫
- AndoridSQLite資料庫開發基礎教程(4)SQLite資料庫
- 資料庫開發基礎---常見面試題資料庫面試題
- 資料庫查詢資料庫
- oracle資料庫sql查詢檢視第二次查詢很慢Oracle資料庫SQL
- 資料庫 - 資料查詢資料庫
- 併發查詢資料庫問題資料庫
- 資料庫資料的查詢----連線查詢資料庫
- 測試驅動開發(TDD)—— 資料庫查詢篇資料庫
- 『動善時』JMeter基礎 — 43、JMeter對資料庫的查詢操作JMeter資料庫
- Andorid SQLite資料庫開發基礎教程(3)SQLite資料庫
- Andorid SQLite資料庫開發基礎教程(2)SQLite資料庫
- Andorid SQLite資料庫開發基礎教程(1)SQLite資料庫
- 資料庫高階查詢之子查詢資料庫
- SQL Server:基於WEB的資料庫查詢SQLServerWeb資料庫
- 求助:資料庫查詢資料庫
- ThinkPHP 資料庫查詢PHP資料庫
- 查詢資料庫大小資料庫
- 資料庫排序查詢資料庫排序
- Jemter查詢資料庫資料庫
- 資料庫 - 連線查詢、巢狀查詢、集合查詢資料庫巢狀