Re: Complex query - Mailing list pgsql-general

From Leonardo M. Ramé
Subject Re: Complex query
Date
Msg-id 20140331192242.GD10833@leonardo-laptop
Whole thread Raw
In response to Re: Complex query  (David Johnston <polobo@yahoo.com>)
List pgsql-general
On 2014-03-31 12:16:53 -0700, David Johnston wrote:
> Leonardo M. Ramé-2 wrote
> > select lag.id, lag.idtask, lag.code, lag.lg from (select idtask, code, id,
> > lag(code, -1) over () as lg  from tasks_test) as lag
>
> First you want to include an ORDER BY in the OVER(...) clause, and probably
> a PARTITION BY as well.
>
> Then you move that to a sub-query (for example):
>
> SELECT *
> FROM tbl
> WHERE tbl.idtask IN (
> SELECT lag.idtask FROM ( lag_query_here ) lag WHERE lag.code = 'T' and
> lag.lg = 'S'
> );
>
> David J.
>

Great!, that's what I needed, thank you.

--
Leonardo M. Ramé
Medical IT - Griensu S.A.
Av. Colón 636 - Piso 8 Of. A
X5000EPT -- Córdoba
Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
Cel.: +54 9 (011) 40871877



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [ADMIN]openvz and shared memory trouble
Next
From: Ben Hoyt
Date:
Subject: Getting sequence-generated IDs from multiple row insert