thanks tim. will read up on rank() and pl/pgsql.
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных