Christian Buettner-167247 (1/19/2012)
WayneS (1/18/2012)
Comments posted to this topic are about the item <A HREF="/articles/SQL+Server+2012/76704/">The new Analytic functions in SQL Server 2012</A>Great information, thanks for that.
To me it was not clear immediately, what the difference between the MAX Aggregate Window Function and LAST_VALUE(X) was. In the end
MAX(x) OVER (PARTITION BY y)
should return the same asFIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY X DESC)
But obviously, the MAX / MIN Aggregate Window Functions do not allow you to order your partition by a different column before applying the aggregate. (And it actually does not really make sense to impose a different order on MAX or MIN.)
So the whole point of FIRST_VALUE and LAST_VALUE seem to be:
FIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY SomeOtherColumn DESC)
Any other points I may have missed?
Actually...
this article only talks about the Analytic functions. You might want to look at my previous article The OVER Clause enhancements in SQL Server code named “Denali”, CTP3[/url].
Basically, the MIN/MAX functions DO allow you to order your partition by a different column. But let's talk about this "over there"... it's more appropriate there.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes