mlsb.net
当前位置:首页 >> 关于SQL递归查询问题 >>

关于SQL递归查询问题

我来测一下,等会上传结果 你还有一个表没用到。 WITH cte AS ( SELECT RegionID,RegionName,RegionPID FROM [tbRegionTree] WHERE regionPID='01' UNION ALL SELECT d.RegionID,d.RegionName,d.RegionPID FROM cte c inner JOIN [tbRegionTree]...

在SQL SERVER 2000 中你可以先一些自定义函数,或一些存储过程,实现递归: select level,TypeName from ProductType t START WITH t.ParentID=0 CONNECT BY PRIOR t.ProductTypeID= t.ParentID;

sql 递归查询的方法: 方法一:T-SQL递归查询 with Dep as ( select Id,DeptCode,DeptName from Department where Id=1 union all select d.Id,d.DeptCode,d.DeptName from Dep inner join Department d on dep.Id = d.ParentDeptId ) select * ...

with tt(select 语句1 --初始化 union all select 语句2) select * from tt 在select 语句2中from的表里关联with后面的表名tt就形成递推了。

假如表数据如下: t_id p_id node 1 a 2 1 b 3 1 c 4 2 d 5 2 e 树的形状为 a | \ b c | \ d e 递归代码为:select t_id, p_id, node from tree connect by prior t_id = p_id start with t_id = 1

一、SqlServer 递归查询 1、基本概念 公用表表达式 (CTE) 可以认为是在单个 SELECT、INSERT、UPDATE、DELETE 或 CREATE VIEW 语句的执行范围内定义的临时结果集。公用表表达式可以包括对自身的引用,这种表达式称为递归公用表表达式。 http://ww...

--构造测试数据: 只作演示用 CREATE TABLE [dbo].[Tim_LinqTable]( [Id] int PRIMARY KEY IDENTITY(1,1) NOT NULL, [Name] [varchar](50) NOT NULL, [Parent] int NOT NULL, ) GO INSERT INTO [Tim_LinqTable] SELECT 'A',0 UNION ALL SELECT '...

with district as ( select * from SECFUNMODULE where MENUID='030' union all select a.* from SECFUNMODULE a, district b where a.PMENUID = b.MENUID ), district1 as ( select a.* from district a where a.MENUID in (select PMENUID fro...

//获取表中所有idprotected List getIdList(String sql, Object ... params) { return xxx;} //获取该menu下的所有子节点private List getMenuChildrenIds(long menuId) { String sql = "select menu_id from test_tb where p_id = ? "; return...

因为你的with后面的名称和表的名称一样了,冲突了。 WITH XI_news_Class 改成with 其他名称

网站首页 | 网站地图
All rights reserved Powered by www.mlsb.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com