Re: aggregate function ?

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Raimon Fernandez <coder(at)montx(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: aggregate function ?
Date: 2007-05-18 15:57:20
Message-ID: 674258.30957.qm@web31808.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


--- Raimon Fernandez <coder(at)montx(dot)com> wrote:
>
> compte: 572 0000 01
> date init: 15/01/2007
> date end: 30/01/2007
>
> The initial sum, would be the compte field plus a date init of the
> year, in that case, 01/01/2007 to the date init, 15/01/2007. Here
> we'll get the SUM of the two values (deure-haver), and this would be
> the initial value of the sum_value to add, so the code would be:
>
> SELECT SUM(deure)-SUM(haver) FROM assentaments WHERE
> assentaments.compte='572000001' and assentaments.data >='2007-01-15'
> and assentaments.data <='2007-01-30';

So if I understand you correctly:

SELECT oid, concepte, deure, haver,
delta_sum + ( SELECT SUM( COALESCE( A3.deure ) - COALESCE ( A3.haver ) )
FROM Assentaments A3
WHERE A3.compte = '572000001'
AND A1.data BETWEEN '2007-01-15' AND '2007-01-30' ) AS starting_Sum
FROM( 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 ) AS Summed_Assentaments( oid, concepte, deure, haver, delta_sum );

Regards,
Richard Broersma Jr.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message coder 2007-05-18 17:32:29 Re: [NOVICE] aggregate function ?
Previous Message Raimon Fernandez 2007-05-18 06:35:50 Re: aggregate function ?