Ranking Results

From: "Craig" <postgresql(at)bryden(dot)co(dot)za>
To: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Ranking Results
Date: 2005-09-13 20:07:45
Message-ID: 000d01c5b89e$cf1858b0$0300a8c0@amd64
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

I have a query that is grouping by 3 fields and returning a sum of another field. I would also like a further field to be returned that shows a ranking for the records based on the sum field. This should really only be a numbering of the rows returned, since I will do the ordering in an ORDER BY clause

A Simplistic example:

SELECT f1, f2, f3, sum(f4)
FROM TableA
GROUP BY f1, f2, f3
ORDER BY f2,f1,f3

Now I would like to add another field that simply return 1,2,3,4,5,etc.. for each row that is returned.

Can this be done?

Thanks
Craig

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2005-09-13 20:32:51 Re: oracle's first_value function for postgres?
Previous Message Richard Huxton 2005-09-13 19:38:46 Re: Using COPY command when input file contain backslashes?