Re: More wacky grouping
От | Manfred Koizar |
---|---|
Тема | Re: More wacky grouping |
Дата | |
Msg-id | cabq8v0sntirhbn21jd9o2gme1gq2goi7k@4ax.com обсуждение исходный текст |
Ответ на | More wacky grouping ("James Taylor" <jtx@hatesville.com>) |
Список | 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 по дате отправления: