Re: alias question

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Ceasar <ocerda(at)hotmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: alias question
Date: 2001-12-14 14:35:36
Message-ID: 20011214063137.K11758-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 13 Dec 2001, Ceasar wrote:

> I was wondering if you could use an alias to do math calculations: for
> example,
>
> select Bank1,
> (var1 + var2) as calc,
> calc*100 as var2
>
> From......
>
> I keep getting this message that says that calc is not in any of the
> tables in the From statement. Is it possible to use a alias (calc) to
> make further calculations? If so, how? Any help would be greatly
> appreciated.

I don't believe directly. You can fake this somewhat by making a two
level query where the calculation is done in a subselect in from. It
looks however like the above is recursive, var2 depends on calc and calc
depends on var2 (or is var2 also a column name?)
Assuming it is a column, you should be able to do something like

select Bank1, calc, calc*100 as var2 from
(select bank1, (var1+var2) as calc from ... ) ali;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-12-14 14:37:52 Re: [CORE] report a bug
Previous Message Stephan Szabo 2001-12-14 14:31:20 Re: Insert character codes in PosgreSQL with SQL command