Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 0F1722E109C for ; Tue, 13 Nov 2007 11:33:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 80048-04 for ; Tue, 13 Nov 2007 11:33:37 -0400 (AST) Received: from smtp156.iad.emailsrvr.com (smtp156.iad.emailsrvr.com [207.97.245.156]) by postgresql.org (Postfix) with ESMTP id B8F202E0DD0 for ; Tue, 13 Nov 2007 11:33:43 -0400 (AST) Received: from relay5.relay.iad.emailsrvr.com (localhost [127.0.0.1]) by relay5.relay.iad.emailsrvr.com (SMTP Server) with ESMTP id 775E965BCD0; Tue, 13 Nov 2007 10:33:42 -0500 (EST) Received: by relay5.relay.iad.emailsrvr.com (Authenticated sender: erik-AT-myemma.com) with ESMTP id 1D15864FC6C; Tue, 13 Nov 2007 10:33:42 -0500 (EST) In-Reply-To: <473907A4.4060400@gmx.net> References: <0c8501c82575$bd3cf830$8f01010a@iptel.com.ar> <473907A4.4060400@gmx.net> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: Cc: Fernando Hevia , pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable From: Erik Jones Subject: Re: design of tables for sparse data Date: Tue, 13 Nov 2007 09:33:23 -0600 To: Andreas X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/58 X-Sequence-Number: 29586 On Nov 12, 2007, at 8:10 PM, Andreas wrote: > Fernando Hevia schrieb: >>> --- Andreas Wrote: --- >>> ... >>> >>> MY QUESTIONS: >>> >> >> Your questions have a strong "home-work" look. > > Yes but I didn't want to bother everyone with my project's details. > It's more like a CRM. > Up until now I just tried to manage somehow with the sql basics and =20= > now I like to get better. > One interesting thing are crosstabs because I could use them in the =20= > reporting module. > > I used this schoolbook scenario because it's such an easy =20 > example. ;) > > >>> 1) How would I SELECT a report that looks like the first =20 >>> version of >>> the pupil table out of the 3 table design? >>> There must be a nontrivial SELECT statement that combines all 3 =20 >>> tables. >>> >> >> You should check out the JOIN clause in select statements. Simple =20 >> example: >> >> Select t1.col1, t2.col1, t2.col2 >> >from t1 inner join t2 b on (t1.col1 =3D t2.col1) >> > > A simple JOIN won't do the trick. > That would give me something like: > (42, Frank Miller, Maths) > (42, Frank Miller, English) > (42, Frank Miller, Sports) > (43, Suzy Smith, Maths) > (43, Suzy Smith, History) > > But I want it turned around and a bit interpreted like: > > Column heads =3D (ID, Name, Maths, English, Sports, History) > (42, Frank Miller, yes, yes, yes, no ) > (43, Suzy Smith, yes, no, no, yes) You should look into the crosstab contrib package. Erik Jones Software Developer | Emma=AE erik@myemma.com 800.595.4401 or 615.292.5888 615.292.0777 (fax) Emma helps organizations everywhere communicate & market in style. Visit us online at http://www.myemma.com