Re: aggregate function ?

From: Raimon Fernandez <coder(at)montx(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: aggregate function ?
Date: 2007-05-16 16:13:57
Message-ID: 220AA706-5A3E-4014-BC61-D010567A2ED7@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Well, that's perfectly ...

Now I'm going to try to understand how this work ...

In the web page that you refer, it also shows how to do it with a
temporal table/cursor, and I see it's faster there.

You have more options if you need to do some extra operations, but I
see how powerful SQL can be ...

Would be possible with this code to start the sum_value with a
previous value from another SELECT ?

For example, SELECT SUM(deure)-SUM(haver) FROM assentaments WHERE
data<2007-01-01;

thanks again four your help, I really appreciated, really !

regards,

raimon

On 16/05/2007, at 17:45, Richard Broersma Jr wrote:

> If all else fails, look for the answer on google:
> http://www.sqlteam.com/item.asp?ItemID=3856
>
> aparently "ON A1.oid <= A2.oid" should have been:
> "ON A1.oid >= A2.oid".
>
>
> SELECT A1.oid, A1.concepte, A1.deure, A1.haver,
> sum( COALESCE( A2.deure, 0 ) -
> COALESCE( A2.haver, 0 )) AS value_sum
> FROM Assentaments AS A1
> INNER JOIN Assentaments AS A2
> ON A1.oid >= A2.oid
> AND A1.numero = A2.numero
> WHERE A1.numero=11189
> GROUP BY A1.oid, A1.concepte, A1.deure, A1.haver
> ORDER BY A1.oid;
>
>
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Broersma Jr 2007-05-16 16:39:01 Re: aggregate function ?
Previous Message Richard Broersma Jr 2007-05-16 15:45:22 Re: aggregate function ?