Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2dEq-0001p9-Hx for pgsql-sql@arkaria.postgresql.org; Fri, 26 Jul 2013 08:19:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V2dEp-0001tE-VB for pgsql-sql@arkaria.postgresql.org; Fri, 26 Jul 2013 08:19:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2dEn-0001t5-Ug for pgsql-sql@postgresql.org; Fri, 26 Jul 2013 08:18:58 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=mail.ringways.co.uk) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2dEj-0007IN-OG for pgsql-sql@postgresql.org; Fri, 26 Jul 2013 08:18:57 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1V2dEi-0001W9-1k for pgsql-sql@postgresql.org; Fri, 26 Jul 2013 09:18:52 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: value from max row in group by Date: Fri, 26 Jul 2013 09:18:51 +0100 User-Agent: KMail/1.9.10 References: <201307251845.51079.gary.stainburn@ringways.co.uk> <9d70bbaa0ce84bab8c0467c83fbc01c7@BY2PR05MB237.namprd05.prod.outlook.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201307260918.51825.gary.stainburn@ringways.co.uk> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Sorry, but I never thought. I'm developing this on my server I'm developing it for someone else who wants it in a WordPress / MySQL environment (I don't know MySQL). Would this or something similar work in mysql? (Sorry for going O.T.) On Thursday 25 July 2013 19:53:06 Marc Mamin wrote: > >________________________________________ > >Von: pgsql-sql-owner@postgresql.org [pgsql-sql-owner@postgresql.org]" > > im Auftrag von "Venky >Kandaswamy [venky@adchemy.com] > > > >You can use Postgres WINDOW functions for this in several different ways. > > For example, one way of doing it: > > > >select stts_id, last_value(stts_offset) over (partition by stts_id order > > by stts_offset desc) + last_value(stts_duration) over (partition by > > stts_id order by stts_offset desc) from table > >group by stts_id; > > another simple solution with distinct on: > > select distinct on (stts_id, stts_offset) stts_id, > stts_offset+stts_duration from table > order by stts_id, stts_offset desc > > Marc Mamin > -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql