Re: Window function sort order help

From: Dianna Harter <dharter(at)mynewplace(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Window function sort order help
Date: 2011-09-19 21:31:57
Message-ID: 25770AAABEA9A2499B5427E0DCEE9C9B44B1647ED5@BE262.mail.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thank you. It works perfect.

Dianna

Tim Landscheidt < tim(at)tim-landscheidt(dot)de > wrote:

> If I understand the question correctly, try:
>
> | SELECT DISTINCT ON (consumer_id) consumer_id, move_date, history_timestamp
> | FROM (SELECT consumer_id, move_date, history_timestamp,
> | LAG(move_date) OVER (PARTITION BY consumer_id ORDER BY consumer_id, history_timestamp) AS previous_move_date
> | FROM consumer_hist) AS SubQuery
> | WHERE move_date IS DISTINCT FROM previous_move_date
> | ORDER BY consumer_id, history_timestamp DESC;
>
> Tim

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2011-09-20 09:58:20 Combining several CTEs with a recursive CTE
Previous Message boris 2011-09-19 15:49:03 Re: select xpath ...