Marcus Claesson wrote:
> Hi Richard,
>>Just looking at the start of your output, you are missing some rows
>>(a/1/1) and have replaced others (a/2/1 isn't in your data).
> Yes, that's exactly it. There's no mistake. The only column I need to
> update is 'full', by giving every row a new 'full', based on its
> 'score'. The tricky thing is that if a 'name' has several 'parts', then
> all those 'parts' should have the same new 'full' value. Not sure if I'm
> making much sense here...Just ask away if it's still unclear.
OK - so if I re-arrange the columns: (name*, part*, score, full)
The primary key is (name,part), (score) is what you measure and (full)
is just for ordering.
So - you want to update "full" so it reflects the sortorder something like:
SELECT name, max(score) FROM table
GROUP BY name ORDER BY max(score) DESC;
You can then get the order you want with something like:
SELECT t1.name, t1.part, t1.score, t2.order_score
FROM table t1,
SELECT name, max(score) AS order_score
FROM table GROUP BY name
) AS t2
t1.name = t2.name
t2.order_score DESC, t1.part ASC;
Write a small plpgsql function to process the table in that order and
update "full" accordingly. Actually, I'd add a SERIAL primary key and
have a separate table for "full" - that way you can just delete the
sorting values and replace them in one go.
In response to
pgsql-sql by date
|Next:||From: Michael Fuhr||Date: 2004-12-18 09:26:33|
|Subject: Re: get branches & childs from database|
|Previous:||From: RobertD.Stewart||Date: 2004-12-17 15:51:24|
|Subject: Re: Table History|