X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0DF7E9DCC0E for ; Mon, 28 Nov 2005 12:20:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64922-02 for ; Mon, 28 Nov 2005 12:20:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from resmta04.ono.com (smtp.ono.com [62.42.230.12]) by postgresql.org (Postfix) with ESMTP id 298339DCC0C for ; Mon, 28 Nov 2005 12:20:19 -0400 (AST) Received: from Zeus (84.120.17.201) by resmta04.ono.com (7.2.052) id 4377F29600133105 for pgsql-sql@postgresql.org; Mon, 28 Nov 2005 17:20:18 +0100 From: "Mauricio Fernandez A." To: Subject: Anual Query Date: Mon, 28 Nov 2005 17:20:25 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.439 required=5 tests=[AWL=-0.480, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.439 X-Spam-Level: * X-Archive-Number: 200511/260 X-Sequence-Number: 23511 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, Can any of you help me with this query?, I need to retrieve the sum(units) and sum(cost) for each client in every month in the same row, something like this: client|UnJan|CostJan|UnFeb|CostFeb|UnMar|CostMar ... |UnDec|CostDec - -------------------------------------------------------------------- 100058|580 |47384 |746 |87438 |536 |21653 ... |857 |754875 (wrong data, just to show) Now I get this result using several querys (one for month and worse for client too) but this, of course its too expensive. Here is a table sample. orderId | client | date | product | Un | cost - ------------------------------------------------------ 1001299 | 100058 | 20050103 | 759936 | 1 | 2375 1001299 | 100058 | 20050103 | 759928 | 1 | 2375 1001300 | 100078 | 20050103 | 759936 | 1 | 2375 1001301 | 100017 | 20050103 | 759928 | 1 | 2375 1001302 | 100009 | 20050103 | 759936 | 2 | 4750 1001302 | 100009 | 20050203 | 756304 | 1 | 6669 1001303 | 100009 | 20050203 | 759936 | 2 | 4750 1001304 | 100005 | 20050203 | 759936 | 20 | 47500 1001306 | 100013 | 20050203 | 759936 | 2 | 4750 1001306 | 100013 | 20050203 | 759928 | 2 | 4750 1001307 | 100013 | 20050203 | 759936 | 4 | 9500 1001308 | 100013 | 20050203 | 759936 | 2 | 4750 1001309 | 100050 | 20050303 | 759936 | 2 | 4750 1001310 | 100050 | 20050303 | 759936 | 4 | 9500 .... Thanks for any idea. Mauricio Fernández A. Ingeniero de Sistemas U. Autónoma de Manizales -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 6.0.2i iQA/AwUBQ4sgNc4irmZP1c6WEQLcPgCeLQNXphTXFXqVFZcKxrIO7aAfCEMAn397 jOO4lULVn/3bPLm6du7hGJeR =YSsL -----END PGP SIGNATURE-----