X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 81028D1B4F2 for ; Wed, 15 Oct 2003 08:18:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 07600-01 for ; Wed, 15 Oct 2003 05:17:58 -0300 (ADT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 41393D1B508 for ; Wed, 15 Oct 2003 05:17:56 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 1A9gqy-000KZf-0Z; Wed, 15 Oct 2003 09:17:56 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id EA38B161EF; Wed, 15 Oct 2003 09:17:51 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 553B515D92; Wed, 15 Oct 2003 09:17:51 +0100 (BST) From: Richard Huxton To: "Muhyiddin A.M Hayat" , Subject: Re: Create View Date: Wed, 15 Oct 2003 09:17:50 +0100 User-Agent: KMail/1.5 References: <009401c392b7$e5fefe30$1f00a8c0@middinkcomp> In-Reply-To: <009401c392b7$e5fefe30$1f00a8c0@middinkcomp> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310150917.50227.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/172 X-Sequence-Number: 15572 On Wednesday 15 October 2003 02:01, Muhyiddin A.M Hayat wrote: > > Table Billing: > > id trx_date trx_time depart payment_method > billing_amount amount_paid balance creator 1 10/09/2003 > 21:55:02 Resto Visa 13.800,00 > 10.000,00 3.800,00 middink > > Table Payment > > id r trx_date trx_time descriptions > payment_method amount creator 1 10/08/2003 18:17:40 > Payment Cash 2.000,00 middink > > > I would like to create "View " from above table with result look like: > > > trx_date trx_time descriptions > payment_method debet > credit balance creator 10/09/2003 21:55:02 Resto > Billing 13.800,00 Paid: 10.000,00 Visa > 3.800,00 3.800,00 middink 10/08/2003 > 18:17:40 Payment > Cash 2.000,00 > 1.800,00 middink I'm not sure the above makes sense. I don't see any way to connect that particular payment to that particular bill. You also seem to have two different types of information in the billing table (billing *and* payment). Also, the payment seems to be occurring before the bill - which can happen, but there doesn't seem to be any account it is paid into. Generally, there are two ways to do this: 1. Set-returning functions (see the manuals and http://techdocs.postgresql.org) 2. A transaction/account page that you keep up to date in exactly the sort of format you want in your view. Triggers can make sure this happens automatically. Unfortunately, if you're stuck with the tables you've shown us then I don't think you can solve your problem. -- Richard Huxton Archonet Ltd