-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On Jul 28, 2008, at 10:18 PM, Rajarshi Guha wrote:
aid pid nmol
- --- ---
323 100
245 3445
478 12
I can easily do the first step, but am struggling to make the SQL
for the second step. Any pointers would be appreciated
>
> Hi, I have a table of the form
>
> aid pid nmol
> - --- ---
> 123 34
> 245 3445
> 323 100
> 478 12
> 545 14
> 645 200
> 7null null
>
> In general, aid is unique, pid and nmol are non-unique.
>
> What I'm trying to do is to select those rows w
Rajarshi Guha wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi, I have a table of the form
aid pid nmol
- --- ---
123 34
245 3445
323 100
478 12
545 14
645 200
7null null
In general, aid is unique, pid and nmol are non-unique.
What I'm t
Rajarshi Guha wrote:
What I'm trying to do is to select those rows where pid is not null,
grouped by pid.
From within each group I'd like to select the row that has the
maximum value of nmol.
Distinct on should do the job for you.
select distinct on (pid) aid, pid, nmol
from atabl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi, I have a table of the form
aid pid nmol
- --- ---
123 34
245 3445
323 100
478 12
545 14
645 200
7null null
In general, aid is unique, pid and nmol are non-unique.
What I'm trying to do is to sele