1

您好我正在尝试我的查询作为贝洛。请查看两个不同版本的查询及其错误消息。

SELECT first_value(col1) AS 'inv',col2 
FROM dbo.table  
--first_value' is not a recognized built-in function name.  

SELECT dbo.first_value(col1) AS 'inv',col2 
FROM dbo.table  
--Cannot find either column "dbo" or the user-defined function or aggregate "dbo.first", or the name is ambiguous.

SELECT first_value(col1) AS 'inv',col2 
FROM dbo.table 
GROUP BY col2  
--'first' is not a recognized built-in function name.

SELECT dbo.first_value(col1) AS 'inv',col2 
FROM dbo.table 
GROUP BY col2  
--Cannot find either column "dbo" or the user-defined function or aggregate "dbo.first", or the name is ambiguous.  

请任何帮助!

4

1 回答 1

-1

如果您尝试从表中提取顶部/第一条记录,则需要指定将行定义为第一/顶行的条件

SELECT top 1  col1 AS inv,col2  
FROM dbo.table 
ORDER BY col1 --or whatever criteria you need here

据我所知,first_value 似乎是一个 MS SQL Server 2012 函数,它还需要一个排序子句 - http://msdn.microsoft.com/en-us/library/hh213018.aspx

于 2012-04-25T15:06:42.423 回答