使用临时表

时间:2015-11-11 18:39:27

标签: sql sql-server sql-server-2008

insert into #TempUserTable  

查询

;with cte as  
(  
select *,row_number() over(partition by (userid) order by login_time) as   'rowrank'  
from #TempUserTable  
)  

在')'

附近收到错误的错误语法

2 个答案:

答案 0 :(得分:2)

语法看起来很好,只需在最后添加你的选择。

;with cte as
(
    select *,row_number() over(partition by (userid) order by login_time) as 'rowrank'
    from #TempUserTable
)
select * 
from cte 
where rowrank = 1

答案 1 :(得分:1)

;with cte as
(
select *,row_number() over(partition by (userid) order by login_time) as 'rowrank'
from TempUserTable
)
SELECT * 
INTO #tempusertable
FROM cte