Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 6A93A9FB322 for ; Sun, 22 Oct 2006 12:46:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 85839-10 for ; Sun, 22 Oct 2006 15:46:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 26EBE9FB2D3 for ; Sun, 22 Oct 2006 12:46:01 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id k9MFjvVN014982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 22 Oct 2006 09:46:00 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id k9MFjv5d029408; Sun, 22 Oct 2006 09:45:57 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id k9MFjvJ2029407; Sun, 22 Oct 2006 09:45:57 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 22 Oct 2006 09:45:56 -0600 From: Michael Fuhr To: Leendert Paul Diterwich Cc: pgsql-sql@postgresql.org Subject: Re: Crosstab question Message-ID: <20061022154556.GA29357@winnie.fuhr.org> References: <453b5c95.3a026987.2aae.ffffb959@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <453b5c95.3a026987.2aae.ffffb959@mx.google.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=SPF_PASS, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200610/198 X-Sequence-Number: 26587 On Sun, Oct 22, 2006 at 01:57:09PM +0200, Leendert Paul Diterwich wrote: > The problem is that the data is being shifted when there is no > price for Supplier1 for product 3: > > Productnumber Supplier1 Supplier2 > 2 0.8 0.9 > 3 1.1(WRONG!) > > I'm using this command to retrieve the data: > > select * from crosstab('select int_artnr, int_crednr, flt_inkoopprijs from > artcredinkoopprijzen where > int_crednr = 2 OR int_crednr = 3') as c(int_artnr integer, supp1 float4, > supp2 float4); Try using the crosstab(text source_sql, text category_sql) variant. Unrelated suggestion: prices should probably be numeric instead of floating-point due to the inexactness of the latter. -- Michael Fuhr