首页 > 代码库 > SQL 公用表达式CTE

SQL 公用表达式CTE

一 基本用法

with mywithas(select * from Student )select * from mywith

 

二 递归调用

with mywithas(select ID,UserID,UserName,Age,CreateUser,CreateTime from Student where ID=D8A9D11A-4F95-414A-BE55-DA460A621954union allselect 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

SQL 公用表达式CTE