Two are all functions introduced by SQL SERVER 2012. Used to return the value of a field that gets the last row after grouping and sorting. It's a simple two function. The ORDER by clause is required, and parition by is optional.
There seems to be nothing to say. The result is a problem when testing the Last_value function.
Here is the test script
; withT as(SELECT TOP -Row_number () Over(ORDER byCOLUMN_ID) asNum fromsys.columns)SelectNum,num/Ten asgrp_factor,first_value (num) Over(Partition byNum/Ten Order byNum asfirst_value,last_value (num) Over(Partition byNum/Ten Order byNum asLast_value fromT
According to my prediction, 0-9 of First_value will return 1, and Last_value will return 9. But the situation is that First_value did return 1. However, Last_value returns the same value as the NUM field itself. Didn't figure out what was going on. There seems to be no problem with the statement.
SQL Server->> First_value and Last_value functions