Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2Pmt-0002Rm-HC for pgsql-sql@arkaria.postgresql.org; Thu, 25 Jul 2013 17:57:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V2Pmt-0002Jc-0S for pgsql-sql@arkaria.postgresql.org; Thu, 25 Jul 2013 17:57:15 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2Pmr-0002HX-EG for pgsql-sql@postgresql.org; Thu, 25 Jul 2013 17:57:13 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=mail.ringways.co.uk) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V2Pmp-0007fQ-3U for pgsql-sql@postgresql.org; Thu, 25 Jul 2013 17:57:12 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1V2Pmo-00037U-Fr for pgsql-sql@postgresql.org; Thu, 25 Jul 2013 18:57:10 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: value from max row in group by Date: Thu, 25 Jul 2013 18:57:10 +0100 User-Agent: KMail/1.9.10 References: <201307251845.51079.gary.stainburn@ringways.co.uk> In-Reply-To: <201307251845.51079.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201307251857.10326.gary.stainburn@ringways.co.uk> X-Pg-Spam-Score: 0.8 (/) 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 As usual, once I've asked the question, I find the answer myself. However, it *feels* like there should be a more efficient way. Can anyone comment or suggest a better method? timetable=> select stts_id, stts_offset+stts_duration as total_duration timetable-> from standard_trip_sections timetable-> where (stts_id, stts_offset) in timetable-> (select stts_id, max(stts_offset) from standard_trip_sections group by stts_id); stts_id | total_duration ---------+---------------- 1 | 01:35:00 2 | 01:35:00 3 | 01:08:00 4 | 01:38:00 5 | 01:03:00 6 | 01:06:00 (6 rows) timetable=> -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql