createtable#tb1(stuidint,stunamevarchar(30),teaidint);insertinto#tb1(stuid,stuname,teaid)values(1,'zhou',0),(2,'kong',0),(3,'hong',2),(4,'zhang',1),(5,'liu',4)。
- 情感问答
- 答案列表
sql 递归查询:sql实现递归查询[朗读]
你这样设计的表用递归来显示最恰当我刚刚好有这个的代码发给你参考下吧///<bindsysmenuchild(dr["w_id"].tostring(),ddllist,separtor_);}}sql语句很简单的。
sql递归查询的方法:方法一:t-sql递归查询withdepas(selectid,deptcode,deptnamefromdepartmentwhereid=1unionallselectd.id,d.deptcode,d.deptnamefrom。
withtt(select语句1--初始化unionallselect语句2)select*fromtt在select语句2中from的表里关联with后面的表名tt就形成递推了。
在sqlserver2000中你可以先一些自定义函数,或一些存储过程,实现递归:selectlevel,typenamefromproducttypetstartwitht.parentid=0connectbypriort.producttypeid=t.parentid;