我有 2 個表,表 1 是樹結構。
Table 1:
ID NAME PARENTID
-------------------------
1 Book1 0
2 Page 1
3 Line1 2
4 Line2 2
5 Book2 0
6 Page1 5
7 Page2 5
8 Line1 6
9 Line2 6
Table 2:
ID BOOK PAGE LINE
1 1 2 4
2 5 7 9
我想獲取表 2 中的所有行并在一行中顯示表 1 的名稱
ID BOOK PAGE LINE
1 Book1 Page Line2
2 Book2 Page2 Line2
如果我使用簡單選擇,如何顯示多行和單行中的 1 行的資料不重復。抱歉這個愚蠢的問題。謝謝你的幫助。
uj5u.com熱心網友回復:
使用連接(tbl 是第二個表):
select t1.id,
t2.name book,
t3.name page,
t4.name line
from tbl t1
join treeTbl t2
on t1.book = t2.id
join treeTbl t3
on t3.id=t1.page
join treeTbl t4
on t4.id=t1.line
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/379819.html
標籤:甲骨文
上一篇:從時間段中選擇oraclesql
