Sqlsever 的with as 用法

固定格式with as ()

1个子表

with
aa as (select transid from JDT1 where account =‘100303’ )
意思是把查询到的transid 字段穿传给aa
select TransId into #b from jdt1 where TransId in (select * from aa)

多个子表

with aa as (
select a from test1 where a=‘3’),
bb as (
select a from test1 where a=‘4’)

select * from test2 where a in (select * from aa)
union all
select * from test2 where a in (select * from bb)

Sqlsever 的with as 用法_第1张图片

Sqlsever 的with as 用法_第2张图片

你可能感兴趣的:(SQL,Server)