软件下载吧文章资讯

分类分类

SQL开发知识:SQL Server 通过with as方法查询树型结构

2024-03-12 20:33作者:下载吧

一、with as 公用表表达式

  类似VIEW,但是不并没有创建对象,WITH AS 公用表表达式不创建对象,只能被后随的SELECT语句,其作用:

  1. 实现递归查询(树形结构)

  2. 可以在一个语句中多次引用公用表表达式,使其更加简洁

二、非递归的公共表达式

  可以是定义列或自动列和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

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消