From: | JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Updating a table field with a consecutive number |
Date: | 2011-02-19 01:06:02 |
Message-ID: | AANLkTinyLcB2aomrGoeDqZGsKzxEHRwsh+RQKSmCdT7j@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Let's suppose I have a table like this one but without data in the Position
field:
----------------------------------------------------------------
Date Score Position
----------------------------------------------------------------
Jan. 2, 2011 1000 1
Jan. 2, 2011 999 2
Jan. 3, 2011 1000 1
Jan. 3, 2011 999 2
Jan. 3, 2011 998 3
Jan. 4, 2011 1000 1
Jan. 4, 2011 999 2
Jan. 4, 2011 998 3
Jan. 4, 2011 997 4
As you can see, the records are order by date and each date has a score and,
depending on the score, a position is assign from 1 to n. I suppose I need
to traverse the table ordered by date and score (one record at a time) and
UPDATE the position field starting with 1 until the date changes. At this
point, I would start from position 1 again until the next date change and so
on. At least this is what I imagine I can do. I will appreciate any advice
about a way of achieving my objective.
Respectfully,
Jorge Maldonado
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Wood | 2011-02-19 12:48:16 | Re: Help loading data. Error code page 850 |
Previous Message | Michael Wood | 2011-02-18 19:22:02 | Re: Help loading data. Error code page 850 |