Re: olympics ranking query

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: olympics ranking query
Date: 2004-08-20 17:11:36
Message-ID: 412630C8.5000004@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tom Lane wrote:
>>Challenge question: is there a simpler way to do query #1 (without any
>>PL, and if possible without sequences too?
>
> Can't without sequences AFAIK, but you certainly can do it simpler:
>
> select setval('seq1', 0);
>
> select nextval('seq1'), * from
> (select count(*) as numranker,
> gold, silver, bronze
> from countrymedal
> group by gold, silver, bronze
> order by gold desc, silver desc, bronze desc) ss;

This is not quite the same. The ranks are sequential, but they skip, so
as to match the number of participating countries.

--
dave

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-08-20 17:21:08 Re: olympics ranking query
Previous Message Bruno Wolff III 2004-08-20 17:01:48 Re: olympics ranking query