Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Created March 1, 2017 14:06
Show Gist options
  • Save ramiroaznar/054351ec3eb281b640e0f0adef20f34a to your computer and use it in GitHub Desktop.
Save ramiroaznar/054351ec3eb281b640e0f0adef20f34a to your computer and use it in GitHub Desktop.
Compare columns and select the one which is bigger with PostgreSQL
with temp as (select 1 as a, 2 as b, 3 as c)
select
case when
a > b and a > c then 'a'
when b > a and b > c then 'b'
else 'c' end as bigger
from temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment