@H_502_1@我在sql Server 2012中有一个表,如快照所示:
然后我使用Last_Value()和First Value来获取不同YearMonth的每个EmpID的AverageAmount.脚本如下:
SELECT A.EmpID,First_Value(A.AverageAmount) OVER (PARTITION BY A.EmpID Order by A.DimYearMonthKey asc) AS '200901AvgAmount',Last_Value(A.AverageAmount) OVER (PARTITION BY A.EmpID Order by A.DimYearMonthKey asc) AS '201112AvgAmount' FROM Emp_Amt AS A
但是,此查询的结果是:
在“201112AvgAmount”列中,它显示每个EmpID的不同值,而“200901AvgAmount”具有正确的值.
我的sql脚本有什么问题吗?我在网上做了很多研究,但仍然找不到答案….