Antw: Re: [SQL] group by / having - Mailing list pgsql-sql

From Gerhard Dieringer
Subject Antw: Re: [SQL] group by / having
Date
Msg-id s85e0535.081@kopo001
Whole thread Raw
List 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




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] MINUS emulation?
Next
From: Vladimir Terziev
Date:
Subject: Re: [SQL] select with group by problem