pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: value from max row in group by
Date: Thu, 25 Jul 2013 18:57:10 +0100
Message-ID: <201307251857.10326.gary.stainburn@ringways.co.uk> (raw)
In-Reply-To: <201307251845.51079.gary.stainburn@ringways.co.uk>
References: <201307251845.51079.gary.stainburn@ringways.co.uk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

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



view thread (6+ messages)  latest in thread

Message-ID: <201307251857.10326.gary.stainburn@ringways.co.uk>
Permalink:  ../201307251857.10326.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/201307251857.10326.gary.stainburn@ringways.co.uk

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: value from max row in group by
  In-Reply-To: <201307251857.10326.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox