Please assist me, I need to pick 790 since its in middle but not able to figure it out.
id Value
12 780
123 796
124 790
Thank you in advance
Please assist me, I need to pick 790 since its in middle but not able to figure it out.
id Value
12 780
123 796
124 790
Thank you in advance
This should help to get what you want. Get the average value from your table, then get first record with smallest difference with average value.
SELECT TOP 1 id, value FROM yourTable
ORDER BY ABS(value - (SELECT AVG(value) FROM yourTable))
or using variables, depending on the size of your table
DECLARE @median DECIMAL
SELECT @median = AVG(value) FROM yourTable
SELECT TOP 1 * FROM yourTable
ORDER BY ABS( value - @median)