MS SQLServer多級父子關係資料查詢

2021-05-05 01:42:49 字數 1260 閱讀 3625

1樓:匿名使用者

加多一列層級碼,會簡單很多比如亞洲用『01』 中國用『0101』,北京用『010101『,海定用『01010101』,東城用』01010102『

這樣語句可以

select id as col1,(select name from 表 where code = substring(a.code, 1,2)) as col2,

(select name from 表 where code = substring(a.code, 3,2)) as col3,

(select name from 表 where code = substring(a.code, 5,2)) as col4,

(select name from 表 where code = substring(a.code, 7,2)) as col5

from 表 a where type = 'distric'

不然(select d.name from 表 b, 表 c, 表 d where a.parentid = b.id and b.parentid = c.id

and c.parentid = d.id) as col2,...

寫起來比較麻煩

2樓:神崎橙

select a.id,d.name as col2,c.name as col3,b.name as col4 ,a.name as col5

from tb a

inner join tb b on a.parentid=b.idinner join tb c on b.

parentid=c.idinner join tb d on c.parentid=d.

idwhere a.type='distric'

mysql 一張表父子關係查詢

3樓:

select t1.name,t2.name,t3.name,t4.name

from tb as t1

left join tb as t2 on t2.pid=t1.id and t2.pid=1

left join tb as t3 on t3.pid=t2.id and t3.pid=2

left join tb as t4 on t4.pid=t3.id and t4.pid=3

where pid=0

4樓:劉樹旺

是想要對應人name的人數?

多級列表怎麼設定,word多級列表怎麼設定

開啟word2010文件頁面,在 段落 中單擊 多級列表 按鈕。我們在列表中選擇一種符合實際需要的多級列表編號格式。在第一個編號後面輸入內容,按回車鍵自動生成第二個編號 注意不是第二級編號 接著輸入內容。完成所有內容的輸入後,選中需要更改級別的段落,並再次單擊 多級列表 按鈕。在選單中選擇 更改列表...

如何定義多級列表,word怎麼設定多級列表?

看圖 gif圖太大,顯示不出來,須點選破圖後 為了節省時間前面的步驟我省略了。希望你能看得懂。word中如何自定義多級列表 在word頂部 開始 欄中找到 多級列表 多級列表 選擇 定義新的多級列表 首先選擇要修改的編號級別 接著編輯編號的字型 編號背景為灰色代表該編號為自動編碼 接著設定 此級別的...

本地計算機上的MSSQLSERVER服務啟動後又停止了怎麼解

回答您好親!2.重新啟動sql server mssqlserver 成功謝謝親哦!祝您生活愉快哦!更多1條 sql service 2000資料庫提示錯誤 mssqlserver服務啟動後又停止了 出現此問題的原因為 設定問題造成的。解決的方法和詳細的操作步驟如下 1 第一步,開啟開始選單,然後在...