Re: select & group by

From: Ragnar Hafstað <gnari(at)simnet(dot)is>
To: "Michael L(dot) Hostbaek" <mich(at)the-lab(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: select & group by
Date: 2005-04-04 10:59:15
Message-ID: 1112612355.19933.12.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 2005-04-04 at 10:47 +0000, Ragnar Hafstað wrote:
> On Mon, 2005-04-04 at 12:16 +0200, Michael L. Hostbaek wrote:
> > [problem]
> [slightly broken solution]

I forgot a FROM clause, and you might want to add a
ORDER BY clause, if that is important:

select part,mfg,
sum(CASE WHEN eta is NULL then qty ELSE 0 END) as qty,
sum(CASE WHEN eta is NULL then 0 ELSE qty END) as "qty incoming",
max(price) as "highest price",
min(eta) as eta
from thetable
group by part,mfg
order by part,mfg;

gnari

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael L. Hostbaek 2005-04-04 12:23:34 Re: select & group by
Previous Message Ragnar Hafstað 2005-04-04 10:47:10 Re: select & group by