Re: Complex query

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Complex query
Date: 2014-03-31 19:16:53
Message-ID: 1396293413495-5798087.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Complex-query-tp5798061p5798087.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2014-03-31 19:21:03 Re: [ADMIN]openvz and shared memory trouble
Previous Message Alvaro Herrera 2014-03-31 19:14:19 Re: Wanted: ALTER TRIGGER ... OWNED BY EXTENSION