Re: More wacky grouping - Mailing list pgsql-sql

From Joe Conway
Subject Re: More wacky grouping
Date
Msg-id 3E8D1EF5.8030201@joeconway.com
Whole thread Raw
In response to More wacky grouping  ("James Taylor" <jtx@hatesville.com>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Roberto Mello
Date:
Subject: Re: pesky plpgsql
Next
From: "Tomasz Myrta"
Date:
Subject: Re: can i make this sql query more efficiant?