Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare three columns in a SQL table to get middle value

Tags:

sql

I need to display the middle value of three columns in a sql table.

eg: For data

col1    col2    col3
759     736     773

Then output should be 759.

What is the best way to do it?

like image 567
user28455 Avatar asked Feb 10 '23 07:02

user28455


1 Answers

For Oracle, MySql and Postgres:

select col1 + col2 + col3 - greatest(col1, col2, col3) - least(col1, col2, col3)
like image 82
Bohemian Avatar answered Feb 13 '23 03:02

Bohemian