1
我不确定哪里出错了,但看起来LAST_VALUE函数没有返回所需的结果。我想要做的是如下SQL Server 2012中的LAST_VALUE函数
Create table #temp(
a varchar(10),
b varchar(10),
c datetime
)
insert into #temp
Values('aa','bbb','2014-10-15 16:39:41.000'),
('aa','bbb','2014-10-16 06:00:04.000')
select a,b,c,
FIRST_VALUE(c) over (partition by a, b order by c asc) as first_date,
LAST_VALUE(c) over (partition by a, b order by c asc) as last_date,
row_number() over (partition by a, b order by c asc) as rn
from #temp
我得到的结果如下,它有不同的最后值。
a | b | c | first_date | last_date | rn
aa | bbb | 2014-10-15 16:39:41.000 | 2014-10-15 16:39:41.000 | 2014-10-15 16:39:41.000 | 1
aa | bbb | 2014-10-16 06:00:04.000 | 2014-10-15 16:39:41.000 | 2014-10-16 06:00:04.000 | 2
可能重复[SQL:最后\ _Value()返回错误的结果(但首先\ _Value()工作正常)](http://stackoverflow.com/questions/15388892/sql-last-value-回报 - 错误的结果,而是先价值的作品精细) – 2015-02-11 20:04:14