Re: Some insight on the proper SQL would be appreciated

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Aaron Burnett <aburnett(at)bzzagent(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Some insight on the proper SQL would be appreciated
Date: 2010-06-08 17:56:07
Message-ID: 4C0E8437.2040801@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/8/2010 11:29 AM, Aaron Burnett wrote:
>
> Greetings,
>
> I hope this is the proper list for this, but I am a loss on how to achieve
> one particular set of results.
>
> I have a table which is a list of users who entered a contest. They can
> enter as many times as they want, but only 5 will count. So some users have
> one entry, some have as many as 15.
>

is it possible to add a new column: "isValid integer"

(or something like it, to signify which one's can and cannot be selected)

I was thinking of doing it in two steps, an update to set isValid, then
a select with just "isValid = 1". Not sure how hard the update would be
though.

Oh, wait, I'll bet a window function would be helpful... but you are on
8.2 so I dont think you have them.

I can think of a stored proc that might work, that ok?

Oh, another thought.. if we order it by username, signedup, and then did
something like:

where ... signedup > (select the 5th signedup from users ... )

not 100% how to do the subselect though. I can see min(signedup) or
max(signedup), but not sure how to get the 5th.

Not real helpful, sorry, just some random thoughts

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-06-08 17:56:10 Re: 3rd time is a charm.....right sibling is not next child crash.
Previous Message Francisco Figueiredo Jr. 2010-06-08 17:52:55 Re: Does npgsql have a bunch of bugs with DB enums?