I want to get the top 2 expensive book and least 2 expensive book prices using FIRST_Value & LAST_Value SQL Server
The presence of Nulls is giving incorrect Min price value, I want the Min price to ignore Nulls
Select top 2 FIRST_VALUE(price) Over(Order by price) as MinPrice,
FIRST_VALUE(title) Over (order by price) as MinName,
LAST_VALUE(price) Over (order by price desc) as MaxPrice,
LAST_VALUE(title) over (Order by price desc) as MaxName
from titles;
Getting this output
MINPrice MINName Maxprice MaxName
NULL The Psychology of Computer $22.95 But is it Friendly?
NULL The Psychology of Computer $21.59 Computer Phobic and
Where as the result I am expecting should be
Minprice MinName Maxprice Maxname
$2.99 The Gourmet Microwave $22.95 But is it Friendly?
$2.99 You can Combat stress $21.59 Computer Phobic and
So how do I eliminate NULLs from Min price