Re: Optimal query suggestion needed - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Optimal query suggestion needed
Date
Msg-id 40D19E62.8090406@archonet.com
Whole thread Raw
In response to Optimal query suggestion needed  (Interzone <lists@interzone.gr>)
Responses Re: Optimal query suggestion needed
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Interzone
Date:
Subject: Optimal query suggestion needed
Next
From: Tom Lane
Date:
Subject: Re: use of a composite type in CREATE TABLE?