我有两个查询,Query1:
with cte as (
select
dbo.Cable.*,
row_number() over(partition by dbo.Cable.TagNo order by dbo.Cable.CableRevision desc) as rn
from dbo.Cable
where (dbo.Cable.CableRevision = @CoreRevision )
)
select *
from cte
where rn = 1
还有Query2
with cte as (
select
dbo.Cable.TagNo,dbo.Core.*,
row_number() over(partition by dbo.Core.CoreNo order by dbo.Core.CoreRevision desc) as rn
from dbo.Core INNER JOIN
dbo.Cable ON dbo.Cable.Id = dbo.Core.CableId
where (dbo.Core.CoreRevision <= @CoreRevision )
)
select *
from cte
where rn = 1
这两个查询是相关的Query1.TagNo
,Query2.TagNo
我如何使用连接这两个查询,是否可以使用With
命令来做到这一点?
谢谢