Re: Column as result of subtraction of two other columns?

From: "Mark Cave-Ayland" <m(dot)cave-ayland(at)webbased(dot)co(dot)uk>
To: "'John Sidney-Woollett'" <johnsw(at)wardbrook(dot)com>, "'Bruno Wolff III'" <bruno(at)wolff(dot)to>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Column as result of subtraction of two other columns?
Date: 2004-07-16 15:36:24
Message-ID: 8F4A22E017460A458DB7BBAB65CA6AE5026612@openmanage
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> -----Original Message-----
> From: John Sidney-Woollett [mailto:johnsw(at)wardbrook(dot)com]
> Sent: 16 July 2004 16:22
> To: Bruno Wolff III
> Cc: Mark Cave-Ayland; pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Column as result of subtraction of two
> other columns?
>
>
> Try
>
> select a, b, (b - a) as diff from (
> select 1 as a, 2 as b
> ) as tmp;
>
> John Sidney-Woollett

Hi John,

Brilliant - thanks for this! The reason I would like to do it this way
is because in my real database, both a and b are horribly complex with 6
or more joins, and it seems a waste for the database to calculate both
results again just to give the difference. I'll give this a go on Monday
and shout if I still can't get it to work.

Many thanks,

Mark.

---

Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park
Derriford
Plymouth
PL6 8BX
England

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446

This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-07-16 16:04:54 Re: Column as result of subtraction of two other columns?
Previous Message Jean-Luc Lachance 2004-07-16 15:22:13 Re: Column as result of subtraction of two other columns?