Skip site navigation (1) Skip section navigation (2)

Re: Lowest 2 items per

From: "Relyea, Mike" <Mike(dot)Relyea(at)xerox(dot)com>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Lowest 2 items per
Date: 2012-06-01 15:44:21
Message-ID: AF7D9319B29A0242A33C3BF843BD31330EFB8D61@USA7061MS03.na.xerox.net (view raw or flat)
Thread:
Lists: pgsql-sql
> -----Original Message-----
> From: David Johnston [mailto:polobo(at)yahoo(dot)com]
> Sent: Friday, June 01, 2012 11:13 AM
> To: Relyea, Mike
> Cc: <pgsql-sql(at)postgresql(dot)org>
> Subject: Re: [SQL] Lowest 2 items per
> 
> 
> I would recommend using the "RANK" window function with an appropriate
> partition clause in a sub-query then in the outer query you simply
WHERE
> rank <= 2
> 
> You will need to decide how to deal with ties.
> 
> David J.



David,

I've never used window functions before and rank looks like it'd do the
job quite nicely.  Unfortunately I'm using 8.3 - which I should have
mentioned in my original request but didn't.  Window functions weren't
introduced until 8.4 from what I can tell.

Mike

In response to

Responses

pgsql-sql by date

Next:From: Relyea, MikeDate: 2012-06-01 16:17:50
Subject: Re: Lowest 2 items per
Previous:From: Oliveiros d'Azevedo CristinaDate: 2012-06-01 15:20:32
Subject: Re: Lowest 2 items per

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group