FIRST VALUE
suggest changeFIRST_VALUE returns the first value in an ordered window. With no PARTITION BY, the window is the whole result. If ORDER BY has ties, which row is first is implementation-defined.
SELECT StateProvinceID, Name, TaxRate,
FIRST_VALUE(StateProvinceID)
OVER(ORDER BY TaxRate ASC) AS FirstValue
FROM SalesTaxRate;
In this example, the FIRST_VALUE function is used to return the ID of the state or province with the lowest tax rate. The OVER clause is used to order the tax rates to obtain the lowest rate.
StateProvinceID | Name |TaxRate|FirstValue|
—— | —— |—–|––|
74|Utah State Sales Tax |5.00|74|
36|Minnesota State Sales Tax |6.75|74|
30|Massachusetts State Sales Tax|7.00|74|
1|Canadian GST |7.00|74|
57|Canadian GST |7.00|74|
63|Canadian GST |7.00|74|
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents