Sql Server cross apply和outer apply

with result as(
select t.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
union all
select '5' str
union all
select '6' str
union all
select '7' str
) t
cross apply
(select t2.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
) t2
where t.str = t2.str) t3)
select * from result;
go

with result as(
select t.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
union all
select '5' str
union all
select '6' str
union all
select '7' str
) t
outer apply
(select t2.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
) t2
where t.str = t2.str) t3)
select * from result;
go

select t.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
union all
select '5' str
union all
select '6' str
union all
select '7' str
) t
cross apply
(select t2.str from(
select '1' str
union all
select '2' str
union all
select '3' str
union all
select '4' str
) t2
where t.str = t2.str) t3;
go

 

posted @ 2019-03-18 10:34  ラピスラズリ(Dawn)  阅读(181)  评论(0编辑  收藏  举报