SQL 公用表达式CTE

一 基本用法

with mywith
as(select * from Student )

select * from mywith

 

二 递归调用

with mywith
as(
select ID,UserID,UserName,Age,CreateUser,CreateTime from Student where ID='D8A9D11A-4F95-414A-BE55-DA460A621954'
union all
select a.* from student a join mywith b on a.CreateTime<a.CreateTime
)

select * from mywith 

参考博客http://www.cnblogs.com/smailxiaobai/archive/2012/01/16/2323291.html

posted on 2016-09-28 07:51  biind  阅读(190)  评论(0)    收藏  举报