您好我的问题是我的问题。 请查看两个不同版本的查询及其错误消息。
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.
请任何帮助!
答案 0 :(得分:-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