首頁 >資料庫 >mysql教程 >with as 递归

with as 递归

WBOY
WBOY原創
2016-06-07 14:57:371876瀏覽

withas递归 id|parentid|Code 1|null|S1409110001 2|1|S1409170004 3|2|S1409170006 无 with accountrp AS( SELECT TOP 1 uid,uaccountrpid,ccode from t_accountrp where ccode='S1409170006' UNION ALLSELECT t_accountrp.uid,t_accountrp.uaccountrpid,t_a

with as 递归
id | parentid | Code
1  | null         | S1409110001
2  |1              | S1409170004
3  |2              | S1409170006
with accountrp AS(
  SELECT TOP 1 uid,uaccountrpid,ccode from t_accountrp where ccode='S1409170006' 
	UNION ALL
	SELECT  t_accountrp.uid,t_accountrp.uaccountrpid,t_accountrp.ccode 
		from accountrp inner join t_accountrp on accountrp.uaccountrpid=t_accountrp.uid
 )select  * from accountrp ORDER BY ccode;
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:sql server 取整函数.下一篇:ora01747