偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

SQL遍歷父子關(guān)系表的測(cè)試

數(shù)據(jù)庫(kù) SQL Server
sql遍歷是我們經(jīng)常會(huì)遇到的問(wèn)題,下文對(duì)SQL遍歷父子關(guān)系表進(jìn)行了側(cè)四,如果您對(duì)此方面感興趣的話,不妨一看。

SQL遍歷父子關(guān)系表的方法未必人人都知道,下面就為您介紹一個(gè)SQL遍歷父子關(guān)系表的測(cè)試,希望可以讓您對(duì)SQL遍歷父子關(guān)系表有更深的認(rèn)識(shí)。

--建立測(cè)試環(huán)境

  1. Create Table A  
  2. (ID Int,  
  3. fatherID Int,  
  4. Name Varchar(10)  
  5. )  
  6. Insert A Select 1,        NULL,       'tt'  
  7. Union All Select 2,        1,          'aa'  
  8. Union All Select 3,        1,          'bb'  
  9. Union All Select 4,        2,          'cc'  
  10. Union All Select 5,        2,          'gg'  
  11. Union All Select 6,        4,          'yy'  
  12. Union All Select 7,        4,          'jj'  
  13. Union All Select 8,        7,           'll'  
  14. Union All Select 9,        NULL, 'uu'  
  15. Union All Select 10,       9,         'oo'  
  16. GO 

--建立函數(shù)

  1. Create Function GetChildren(@ID Int)  
  2. Returns @Tree Table (ID Int, fatherID Int, Name Varchar(10))  
  3. As  
  4. Begin  
  5. Insert @Tree Select ID, fatherID, Name From A Where fatherID = @ID  
  6. While @@Rowcount > 0  
  7. Insert @Tree Select A.ID, A.fatherID, A.Name From A A Inner Join @Tree B On A.fatherID = B.ID And A.ID Not In (Select ID From @Tree)  
  8. Return  
  9. End  
  10. GO  

--測(cè)試

  1. Select * From dbo.GetChildren(1)  
  2. GO 

--刪除測(cè)試環(huán)境

  1. Drop Table A  
  2. Drop Function GetChildren 

--結(jié)果

  1. /*  
  2. IDfatherIDName  
  3. 21aa  
  4. 31bb  
  5. 42cc  
  6. 52gg  
  7. 64yy  
  8. 74jj  
  9. 87ll  
  10. */ 

 

 

 

 

【編輯推薦】

SQL Server視圖的使用

SQL SERVER內(nèi)部函數(shù)大全

SQL Server變量賦值的方法

詳解SQL Server全局變量

動(dòng)態(tài)sql中使用臨時(shí)表的實(shí)例

責(zé)任編輯:段燃 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-10-27 15:11:52

oracle遞歸查詢

2019-11-26 09:21:49

區(qū)塊鏈比特幣虛擬貨幣

2018-04-16 15:11:30

2023-11-14 10:03:30

數(shù)據(jù)庫(kù)技術(shù)

2010-09-07 14:36:24

SQL語(yǔ)句

2010-11-12 14:21:15

SQL函數(shù)

2012-02-02 16:13:29

HibernateJava

2010-09-09 13:32:14

SQL函數(shù)遍歷

2010-11-11 10:41:03

sql server遍

2010-11-11 10:53:22

SQL Server遍

2010-11-11 11:00:06

sql server遍

2011-06-02 10:20:09

SQL主從關(guān)系

2020-11-11 10:13:08

PPID欺騙DLL注攻擊

2024-06-27 00:36:06

2024-01-15 07:42:37

Figma協(xié)同編輯算法

2011-08-23 10:54:16

PostgreSQL表空間用戶

2010-09-14 15:51:15

sql遍歷

2024-10-14 09:34:39

vue3通信emit

2010-09-01 11:46:01

DB2臨時(shí)表SQL

2010-11-24 13:11:06

MySQL遍歷數(shù)據(jù)表
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)