如何使用此代码段创建临时表?

时间:2012-10-09 21:16:26

标签: sql sql-server temp-tables

我如何将这个SQL片段作为临时表生成,以便我可以将其他一些东西加入其中?

with MyCTE AS
(
    select *, RANK() OVER (PARTITION BY workplace ORDER BY Total DESC) AS Rank
    from [dbo].[OriginDestination]
)
select * from MyCTE where Rank <= 5

1 个答案:

答案 0 :(得分:3)

像这样:

with MyCTE AS
(
    select *, RANK() OVER (PARTITION BY workplace ORDER BY Total DESC) AS Rank
    from [dbo].[OriginDestination]
)
select *
into #yourTempTable 
from MyCTE 
where Rank <= 5