Calc - Mailing list pgsql-sql

From Muhyiddin A.M Hayat
Subject Calc
Date
Msg-id 002e01c39356$d5885ca0$1f00a8c0@middinkcomp
Whole thread Raw
Responses Re: Calc
Re: Calc
List pgsql-sql
Dear all,
 
I have below table
 
+-----+--------------------+---------------------+
 | id   |    db                    |cr                          |
+-----+--------------------+---------------------+
 |1     |                            | 200                      |
 |2     | 100                    |                              |
 |3     | 100                    |                              |
 |4     | 150                    |                              |
 |5     |                            | 200                      |
 
I Would like to calc that balance, and look like
 
+-----+--------------------+---------------------+-----------+
 | id   |    db                    |cr                          | bal        |
+-----+--------------------+---------------------+-----------+
 |1     |                            | 200                      |200       |
 |2     | 100                    |                              |100       |
 |3     | 100                    |                              |0            |
 |4     | 150                    |                              |-150      |
 |5     |                            | 200                      |50         |
 
 
What can I do to get result like that
 
 
 
 
 
 
 
 
 
 

pgsql-sql by date:

Previous
From: Christopher Browne
Date:
Subject: Re: indexing timestamp fields
Next
From: Steve Crawford
Date:
Subject: Re: Calc