我在分组后得到前1行,我的查询如下。这工作正常,但当我尝试创建一个视图时,我得到一个语法错误。
create view dbo.v_test
as
;With A as
SELECT
col1,col2,col3,
ROW_NUMBER over (PARTITION by col1, col2, col3
order by col4 desc) as RN
from dbo.Test
)
select *
from A
where RN < 1
错误:
&#39 ;;&#39;
附近的语法不正确
答案 0 :(得分:1)
如果是SQL服务器,这样的事情应该有效:
create view dbo.v_test as
With A as
(
SELECT col1,col2,col3, ROW_NUMBER() over ( PARTITION by col1,col2,col3 order by col4 desc ) as RN
from dbo.Test)
select * from A where RN<1
GO