SELECT
    [RowAsc] AS RowAsc,
    [RowDesc] AS RowDesc,
    UnitRate 
FROM
    (SELECT TOP(10)
         JobName AS JobName, Client AS Client,
         AssetClass AS AssetClass, AssetType AS AssetType,    
         AssetSubType AS AssetSubType,
         Component AS Component, 
         ComponentType AS ComponentType, ComponentSubType AS ComponentSubType,
         UnitRate AS UnitRate,
         ROW_NUMBER() OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType 
                            ORDER BY UnitRate ASC) AS [RowAsc],
         ROW_NUMBER() OVER (PARTITION BY JobName, Client, AssetClass, AssetType, AssetSubType, Component, ComponentType, ComponentSubType 
                            ORDER BY UnitRate DESC) AS [RowDesc]
     FROM 
         [dbo].[ReplaceCost_DirectCost_Details] rdd
     WHERE
         client = 'APV_Ballina_Shire_Council_Old'  
         AND UnitRate IS NOT NULL
         AND UnitRate <> 0) x
WHERE    
    RowAsc IN (RowDesc, RowDesc - 1, RowDesc + 1)
I have this script to get the median of UnitRate but it gives me wrong result for median.I have 10 rows and want to get the median of UnitRate for those 10 rows. Thanks in advance for your help.
 
     
    