Re: More wacky grouping - Mailing list pgsql-sql

From Manfred Koizar
Subject Re: More wacky grouping
Date
Msg-id cabq8v0sntirhbn21jd9o2gme1gq2goi7k@4ax.com
Whole thread Raw
In response to More wacky grouping  ("James Taylor" <jtx@hatesville.com>)
List pgsql-sql
On Thu, 3 Apr 2003 16:29:08 -0800, "James Taylor" <jtx@hatesville.com>
wrote:
>My table looks something like this:
>
>Id | id_customer | id_datatype | content
>----------------------------------------
>1  | 25          | 1           | John
>2  | 25          | 2           | Globochem
>3  | 25          | 3           | 845.92
>[...]
>Datatype 1 = Name, 2 = Company, 3 = account balance.
>
>I need to do an aggregate function on content where id_datatype = 3, and
>then group by content where id_datatype = 2

SELECT c.content AS "Company", sum(b.content::float) AS "Sum" FROM james AS c LEFT JOIN james AS b      ON
(c.id_customer= b.id_customer AND b.id_datatype = 3)WHERE c.id_datatype = 2GROUP BY c.content;
 

should work, if there is exactly one row with id_datatype = 2 for each
id_customer.

ServusManfred



pgsql-sql by date:

Previous
From: "Tomasz Myrta"
Date:
Subject: Re: can i make this sql query more efficiant?
Next
From: Christoph Haller
Date:
Subject: Re: string variable with spaces in psql