Re: Newbie question re SQL

From: john(at)localhost(dot)localdomain (john)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Newbie question re SQL
Date: 2002-03-02 12:52:31
Message-ID: slrna81j05.gqr.orangefree89@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 2 Mar 2002 00:38:48 +0000 (UTC), Lee Harr
<missive(at)frontiernet(dot)net> wrote:

>> Quan Price Cost
>>==== ===== ====
>> 300 125 37,500
>> 500 135 67,500
>> (100) 110 (13,125) <-- how do you get this number?

When I sell a security, to calculate the cost of the remaining
identical securities, I must subtract from my total cost before the
sale the number of units sold * their cost per unit (not their fair
market value at the time of the sale).

> First, I would not keep the cost as a field in the table, you can
> always get that from quan * price, right?

Agreed. Unless, of course, I can't figure out how to get SQL to
calculate cost automatically!

> SELECT sum(quan*price) FROM trans;

Except that this isn't right because, as discussed above, when I sell,
the price at which I sell is the fair market value of each of my units
and not my cost per unit.

Thanks for your response.

--
John

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Fitzmyers 2002-03-02 14:44:02 Re: where is my bottleneck?
Previous Message Holger Marzen 2002-03-02 11:15:19 Re: Shared buffers vs large files