Re: SQL command for value comparison

From: Tod McQuillin <devin(at)spamcop(dot)net>
To: <Patricia_Leong(at)tecsg(dot)com(dot)sg>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL command for value comparison
Date: 2001-01-12 01:36:16
Message-ID: Pine.GSO.4.31.0101111934400.578-100000@sysadmin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 12 Jan 2001 Patricia_Leong(at)tecsg(dot)com(dot)sg wrote:

> I would like to compare 2 attributes before display the result using SQL command
>
> e.g new_due_date old_due_date result to display
> -----------------------------------------------------------
> 11 Feb 2001 15 Feb 2001 in
> 12 Feb 2001 08 Feb 2001 out
>
> "select decode((new_due_date<old_due_date),'in','out') from XYZ" will not be
> working as decode only compare exact value.

Try this:

SELECT new_due_date, old_due_date, CASE WHEN new_due_date < old_due_date
THEN 'in' ELSE 'out' END FROM XYZ;
--
Tod McQuillin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Cheng 2001-01-12 02:09:50 Re: xml middleware
Previous Message Mikheev, Vadim 2001-01-12 01:19:29 RE: Re: Loading optimization