FIRST VALUE

suggest change

FIRST_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|

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents