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-26 08:18:51
Message-ID: 201307260918.51825.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)postgresql(dot)org [pgsql-sql-owner(at)postgresql(dot)org]&quot;
> > im Auftrag von &quot;Venky >Kandaswamy [venky(at)adchemy(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message JORGE MALDONADO 2013-07-26 21:44:05 Unique index and unique constraint
Previous Message Marc Mamin 2013-07-25 18:53:06 Re: value from max row in group by