一、with as 公用表表达式
作者: 官方时时彩app下载-数据库 发布:2020-03-11
一、with as 公用表表明式
就好像VIEW,可是不并不曾创立对象,WITH AS 公用表表明式不创建对象,只可以被后随的SELECT语句,其遵守:
得以完毕递归查询(树形布局卡塔尔国
能够在一个讲话中一再引用公用表表明式,使其进一层精简
二、非递归的集体表达式
能够是定义列或自动列和select into 效果大概
--指定列with withTmp1 (code,cName)as( select id,Name from ClassUnis)select * from withTmp1--自动列with withTmp2 as( select * from ClassUnis where Author = 'system')select * from withTmp2
三、递归的办法
通过UNION ALL 连接部分。通过连续几天本人whit as 成立的表明式,它的接连条件便是递归的准绳。能够从根节点往下搜寻,从子节点往父节点查找。只要求颠倒一下连接条件。举例代码中标准改为t.ID = c.ParentId就可以
with tree as( --0 as Level 定义树的层级,从0开始 select *,0 as Level from ClassUnis where ParentId is null union all --t.Level + 1每递归一次层级递增 select c.*,t.Level + 1 from ClassUnis c,tree t where c.ParentId = t.ID --from ClassUnis c inner join tree t on c.ParentId = t.ID)select * from tree where Author not like'%/%'
还是可以透过option(maxrecursion Number卡塔尔(قطر 设置最大递归次数。举个例子上诉结果Level 最大值为2意味着递归五遍。大家设置其值为1
with tree as( select *,0 as Level from ClassUnis where ParentId is null union all select c.*,t.Level + 1 from ClassUnis c,tree t where c.ParentId = t.ID)select * from tree where Author not like'%/%' option(maxrecursion 1)
好了那篇小说就介绍到那了,希望能扶植到您。
本文由时时彩平台发布于官方时时彩app下载-数据库,转载请注明出处:一、with as 公用表表达式
关键词:
上一篇:接下的的工作需要配置Sqlserver数据库允许远程访
下一篇:没有了
下一篇:没有了