Re: maximum count of contiguous years

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: maximum count of contiguous years
Date: 2009-09-03 11:46:23
Message-ID: m3eiqogsj4.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

gorsa <gorsa(dot)1972(at)gmail(dot)com> wrote:

> [...]
> is there a select statement containing 'AND award_year BETWEEN 1994
> AND 2002' that could generate the following?
> scholar_id consistent_yrs
> 1 4
> 2 5
> 3 2

You could either do some wild fancy query where you parti-
tion the data by scholar_id, then by award_year, then filter
on the condition that the sum of award_year and RANK() (?)
less one equals the current award_year, find the maximum of
those, ...

... or you could just write a short function in your ap-
plication (or a set-returning PL/pgSQL function if your ap-
plication is dumb).

Tim

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message S Arvind 2009-09-03 12:08:47 Data folder in differnet filesystem
Previous Message Merlin Moncure 2009-09-03 11:39:11 Re: To pass schemaname as a function parameter