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 9365FD1B17B for ; Thu, 5 Aug 2004 14:20:27 -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 25781-10 for ; Thu, 5 Aug 2004 17:20:17 +0000 (GMT) Received: from misav06.sasknet.sk.ca (misav06.sasknet.sk.ca [142.165.20.170]) by svr1.postgresql.org (Postfix) with ESMTP id 24DCFD1B171 for ; Thu, 5 Aug 2004 14:20:10 -0300 (ADT) Received: from thyme.sasktel.net ([142.165.20.198]) by misav06 with InterScan Messaging Security Suite; Thu, 05 Aug 2004 11:20:07 -0600 Received: from borderveygqj37 (hssx-estv-30-169.sasknet.sk.ca [142.165.30.169]) by thyme.sasktel.net (SaskTel eMessaging Service) with ESMTPA id <0I1Z009BWHHATA@thyme.sasktel.net> for pgsql-sql@postgresql.org; Thu, 05 Aug 2004 11:20:02 -0600 (CST) Date: Thu, 05 Aug 2004 11:21:05 -0600 From: Caleb Simonyi-Gindele Subject: contrib/tablefunc crosstab To: pgsql-sql@postgresql.org Message-id: <000001c47b10$97178250$c201a8c0@borderveygqj37> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Mailer: Microsoft Outlook, Build 10.0.6626 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Importance: Normal X-Priority: 3 (Normal) X-MSMail-priority: Normal 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: 200408/30 X-Sequence-Number: 18527 Hi, I am using the crosstab function by Joe Conway and I am having a problem that could be my fault but I'm not sure. My query/result is: atc=# SELECT * FROM crosstab('SELECT cli_tran_trans_date, TRIM(dat_staff_code) AS dat_staff_code, SUM(cli_tran_amount) from vetpmardet WHERE cli_tran_trans_date BETWEEN ''2003-06-01'' AND ''2003-06-05'' AND TRIM(dat_staff_code) NOT LIKE '''' GROUP BY cli_tran_trans_date, dat_staff_code ORDER BY 1,2;',5) AS vetpmardet(date date, vet1 numeric, vet2 numeric, vet3 numeric, vet4 numeric, vet5 numeric); date | vet1 | vet2 | vet3 | vet4 | vet5 ------------+--------+---------+---------+--------+-------- 2003-06-01 | 561.99 | | | | 2003-06-02 | 418.43 | 548.10 | 790.16 | 54.24 | 467.07 2003-06-03 | 518.62 | 2115.57 | 630.83 | 195.74 | 548.26 2003-06-04 | 870.52 | 346.49 | 393.77 | 470.02 | 2003-06-05 | 74.37 | 3555.10 | 1248.69 | 758.18 | (5 rows) My problem is that the rows are populated from right to left irrespective of the column. So the $561.99 in vet1 actually belongs to vet2. There are never any blank cells in the middle or start of a row - they always come at the end. How do I get the amount for that date into the appropriate column? I am using 7.4.3 Caleb