-1

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

1 Answers1

0

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) 
Jonathan Hamel
  • 1,393
  • 13
  • 18