Re: How can I produce the following desired result?

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: aicean <aicean(at)netspeed-tech(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How can I produce the following desired result?
Date: 2003-10-15 15:36:13
Message-ID: 3F8D696D.FA5BFA0D@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

select distinct on( goodid) * from table order by goodid, storehistoryid
desc, totalnum, operationdate;

> aicean wrote:
>
> How can I produce the following desired result?
>
> goodid totalnum operationdate storehistoryid
> 132 35.000 09-28-2003 66
> 135 11.500 09-28-2003 61
> 132 35.000 09-27-2003 60
> 135 11.000 09-28-2003 59
> 135 12.000 09-28-2003 58
> 134 100.000 09-28-2003 57
> 134 112.000 09-27-2003 56
> 131 0.000 09-26-2003 54
> 131 33.000 09-26-2003 51
> 131 -2.000 09-26-2003 50
> 3 550.000 09-26-2003 49
> 3 52.000 09-26-2003 48
> 132 35.000 09-27-2003 42
> 3 124.000 09-25-2003 41
> 131 59.000 09-25-2003 40
> 132 57.000 09-26-2003 39
> 131 2.000 09-24-2003 38
> 3 2.000 09-20-2003 23
>
> result:
> goodid totalnum operationdate storehistoryid
> 132 35.000 09-28-2003 66
> 135 11.500 09-28-2003 61
> 134 100.000 09-28-2003 57
> 131 0.000 09-26-2003 54
> 3 550.000 09-26-2003 49
>
> I need to select rows which storehistoryid is max as the same
> goodid .
>
>
> Thanks in advance
>
>
> aicean
> Mailto:aicean(at)netspeed-tech(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jean-Luc Lachance 2003-10-15 15:42:59 Re: Sorting problem
Previous Message greg 2003-10-15 14:48:37 Re: How can I produce the following desired result?