Antw: Re: [SQL] group by / having

From: "Gerhard Dieringer" <DieringG(at)eba-haus(dot)de>
To: <tesio(at)easynet(dot)fr>
Cc: "<"<pgsql-sql(at)postgresql(dot)org>
Subject: Antw: Re: [SQL] group by / having
Date: 1999-12-20 09:30:10
Message-ID: s85e0535.081@kopo001
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> X Y Z
> 1 1 A
> 1 2 B
> 2 1 C
> 3 1 D
> 3 2 E
> 3 3 F
>
> I want one line for each X value where the Y value is minimal, and I want
> to get the T column also.

select T1.X, T1.Y, T1.Z
from T T1
where T1.Y=(select min(T2.Y)
from T T2
where T1.X = T2.X);

should give you the right answer (not tested)

Gerhard

Browse pgsql-sql by date

  From Date Subject
Next Message Vladimir Terziev 1999-12-20 09:58:10 Re: [SQL] select with group by problem
Previous Message Tom Lane 1999-12-20 03:10:48 Re: [SQL] MINUS emulation?