Re: value from max row in group by

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: value from max row in group by
Date: 2013-07-25 17:57:10
Message-ID: 201307251857.10326.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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=>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message bricklen 2013-07-25 17:58:53 Re: value from max row in group by
Previous Message Gary Stainburn 2013-07-25 17:45:51 value from max row in group by