Please help: How to determine largest of two numbers in a query?

From: Greg Youngblood <YoungblG(at)houstoncellular(dot)com>
To: "'PostgreSQL SQL List'" <pgsql-sql(at)postgresql(dot)org>
Subject: Please help: How to determine largest of two numbers in a query?
Date: 1998-12-02 21:55:17
Message-ID: 2B9713A99045D211BB4E0008C75668692EA70C@SCORPEXC1.houstoncell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a table with the following structure:
yyyymmdd int4
key char(16)
value1 int4
value2 int4

with the following sample data:
yyyymmdd key value1 value2
19981201 hello 32 16
19981201 bye 29 64
19981202 hello 16 20
19981202 bye 23 13

What I need is to select the greatest between value1 and value2, so the
answer would be:
yyyymmdd key value
19981201 hello 32
19981201 bye 64
19981202 hello 20
19981202 bye 23

I can do this via ODBC using access by creating a column which is defined as
IF(value1>value2,value1,value2) but that doesn't work in psql.

How can I make this work in psql?

Thanks
Greg

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Adam Maddock 1998-12-03 01:45:52 Re: [SQL] Please help: How to determine largest of two numbers in a query?
Previous Message Gregory W Burnham 1998-12-02 16:55:28 Re: [SQL] Odd characters in inserted data...