首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用SQL兑现递归

2012-07-20 
用SQL实现递归单表:select t.typeId,t.typeName,t.parentId from t_data tstart with t.typeId 3connect

用SQL实现递归

单表:

select t.typeId,t.typeName,t.parentId from t_data t
start with t.typeId = 3
connect by prior t.typeId = t.parentid

?

关联表:t_ues_pic_rescategory目录表,t_ues_resource 资源表 关联列categoryId

该语句实现递归查询某个目录(包括子目录)下所有资源

select r.*, tp.categoryname
? from t_ues_resource r,
?????? (select t.categoryid, t.categoryname
????????? from t_ues_pic_rescategory t
???????? start with t.categoryid = 27
??????? connect by prior t.categoryid = t.parentid) tp
?where r.categoryid = tp.categoryid
?order by r.uploadtime desc

热点排行