X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5FEC6D1B1B4 for ; Thu, 17 Jun 2004 10:36:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91125-09 for ; Thu, 17 Jun 2004 13:36:44 +0000 (GMT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id 4525DD1B4F4 for ; Thu, 17 Jun 2004 10:36:34 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 1Bax4G-00041z-0U; Thu, 17 Jun 2004 14:36:36 +0100 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id C888016CCF; Thu, 17 Jun 2004 14:36:34 +0100 (BST) Message-ID: <40D19E62.8090406@archonet.com> Date: Thu, 17 Jun 2004 14:36:34 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.7 (X11/20040615) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Interzone Cc: pgsql-sql@postgresql.org Subject: Re: Optimal query suggestion needed References: <40D1AEB0.1010604@interzone.gr> In-Reply-To: <40D1AEB0.1010604@interzone.gr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/147 X-Sequence-Number: 18092 Interzone wrote: > Hi all, > > I'm trying to create a view for a client, but I'm failing miserably so I > thought I'ld ask for some help. The initial analysis was quite > complicated, and that specific need never came up until recently, and > unfortunately, changing the tables is probably not an option :( > > > Given the tables : > > create table t0 ( > code integer, > address varchar, > mun integer > ) > > create table t1 ( > code integer, > pname varchar > ); > > create table t2 ( > code integer, > t0_fk integer, > t1_fk integer, > avail bool > ); > > > I want to create a view that will have: > from table t0 the elements "code", "address" and "mun" > from table t1 the elements "code" and "pname" > from table t2 the total number of elements, and the total number of > elements where avail = true, for every value t0_fk (foreign key to t0) > and t1_fk (foreigh key to t1). So there's no connection between column "code" in any of the tables? I'm confused as to the correlation between t0 and t1. I'm also not clear what t2.code is supposed to be. Could you give a short (5 rows each) example of the contents of the tables and the expected results? -- Richard Huxton Archonet Ltd