X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D406C474E44 for ; Fri, 4 Apr 2003 00:57:50 -0500 (EST) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by postgresql.org (Postfix) with ESMTP id F39F9474E42 for ; Fri, 4 Apr 2003 00:57:48 -0500 (EST) Received: from [192.168.5.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.4) with ESMTP-TLS id 1694495; Thu, 03 Apr 2003 22:33:22 -0800 Message-ID: <3E8D1EF5.8030201@joeconway.com> Date: Thu, 03 Apr 2003 21:58:13 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: James Taylor Cc: pgsql-sql@postgresql.org Subject: Re: More wacky grouping References: <002601c2fa41$3a88d760$4500a8c0@theplague> In-Reply-To: <002601c2fa41$3a88d760$4500a8c0@theplague> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-38.0 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/61 X-Sequence-Number: 12762 James Taylor wrote: > So, say I wanted to do a sum function, it would end up with something > like: > > Company | Sum > ------------------- > Globochem | 1130.84 > Toxichem | 1239.47 > Same crosstab function mentioned the other day: select company, sum(acct_bal) as "sum" from (select name, company, acct_bal from crosstab('select id_customer, id_datatype, content from mytable order by 1','select distinct id_datatype from mytable') as (id_customer int, name text, company text, acct_bal numeric)) as ss group by company; company | sum -----------+--------- Toxichem | 1239.47 Globochem | 1130.84 (2 rows) HTH, Joe