当前位置:Gxlcms > mysql > withas递归

withas递归

时间:2021-07-01 10:21:17 帮助过:44人阅读

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 <无>
  1. with accountrp AS(
  2. SELECT TOP 1 uid,uaccountrpid,ccode from t_accountrp where ccode='S1409170006'
  3. UNION ALL
  4. SELECT t_accountrp.uid,t_accountrp.uaccountrpid,t_accountrp.ccode
  5. from accountrp inner join t_accountrp on accountrp.uaccountrpid=t_accountrp.uid
  6. )select * from accountrp ORDER BY ccode;

人气教程排行