Re: maximum count of contiguous years - Mailing list pgsql-general

From Tim Landscheidt
Subject Re: maximum count of contiguous years
Date
Msg-id m3eiqogsj4.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to maximum count of contiguous years  (gorsa <gorsa.1972@gmail.com>)
Responses Re: maximum count of contiguous years
List pgsql-general
gorsa <gorsa.1972@gmail.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

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: To pass schemaname as a function parameter
Next
From: S Arvind
Date:
Subject: Data folder in differnet filesystem