Re: Duplicate counting - Mailing list pgsql-general

From Aaron Bingham
Subject Re: Duplicate counting
Date
Msg-id 41EFB6F0.8010204@cenix-bioscience.com
Whole thread Raw
In response to Duplicate counting  (Jiří Němec <konference@menea.cz>)
List pgsql-general
Jiří Němec wrote:
> Hello all,
>
> I wrote a function which counts price of product from retail price and
> discount. It works. But I need to count price with tax of same
> product. The best way is to use counted price and add only a tax. I
> would like to do by this way:
>
> SELECT count_price(retail, discount) AS price, count_price_tax(price,
> tax) FROM foo.
>
> But PostgreSQL reports that "price" column doesn't exist. It doesn't
> exist, but is counted by first calling "count_price()" function.
>
> Is there some way how I shouldn't count these prices twice and use
> just counted price?

It's not quite clear to me what count_price and count_price_tax are
supposed to do.  Does count_price_tax return the equivalent of
price*(1.0+tax) (or maybe price*tax)?  If so, one way to do it is to use
a sub-query like this:

SELECT price, count_price_tax(price, tax) FROM (SELECT
count_price(retail, discount) AS price, tax FROM foo) AS bar;

--
--------------------------------------------------------------------
Aaron Bingham
Application Developer
Cenix BioScience GmbH
--------------------------------------------------------------------


pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: How to manually insert an UTF-8 character into an SQL statement?
Next
From: "Frank D. Engel, Jr."
Date:
Subject: Re: Best Linux Distribution