Received: from web20609.mail.yahoo.com (web20609.mail.yahoo.com [216.136.226.167]) by postgresql.org (8.11.3/8.11.4) with SMTP id fBBCsgm69082 for ; Tue, 11 Dec 2001 07:54:43 -0500 (EST) (envelope-from mr_ocp@yahoo.com) Message-ID: <20011211125445.96186.qmail@web20609.mail.yahoo.com> Received: from [24.112.241.253] by web20609.mail.yahoo.com via HTTP; Tue, 11 Dec 2001 23:54:45 EST Date: Tue, 11 Dec 2001 23:54:45 +1100 (EST) From: =?iso-8859-1?q?Mr=20OCP?= Subject: Please help me write this query or function To: pgsql-admin@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Archive-Number: 200112/82 X-Sequence-Number: 2805 Hi We have a table like follows: id, account_name, amount, action_type The amount field has both debit and credit entires and action_type defines the type of transaction ( debit or credit), debit entries have negative '-' symbol before the amount. where there are multipble transaction for the same id, I need to write a query as under: select id, amount(credit), amount(debit), amount credit - amount debit from table where id is the same; Its making it difficult for me because the amount field has both debit and credit entries, your ideas, codes or sql will be much appreciated. Thanks Mike http://shopping.yahoo.com.au - Yahoo! Shopping - Free CDs for thousands of Priority Shoppers!