SQLSERVER 2005 遞歸查詢

項目中有用戶組表UserGroup如下: 其中PID表示當前組的上級組 表數據如下: 現在想查詢出頂級組[沒有上級組叫頂級組]A1組的所有子孫組ID,SQL如下: --查詢子節點 with RTD1 as( select id ,pid from UserGroup ), RTD2 as( select * from RTD1 where id=6 union all select RTD1.*
相關文章
相關標籤/搜索