Re: How to find out top 3 records in each location

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>, wen tseng <went(at)hteamericas(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to find out top 3 records in each location
Date: 2006-11-20 17:57:41
Message-ID: 713709.88122.qm@web31813.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Oops, I made a mistake the sub-selects should be item not sales...

> SELECT
> A1.location,
> ( select item
^^^^
> from sales
> where location = A1.location
> order by sales desc
> limit 1
> ) as TOP1,
> ( select item
^^^^
> from sales
> where location = A1.location
> order by sales desc
> limit 1 offset 1
> ) as Top2,
> ( select item
^^^^
> from sales
> where location = A1.location
> order by sales desc
> limit 1 offset 2
> ) as Top3
>
>
> FROM
> ( SELECT location
> from sales
> group by location
> ) AS A1
> ;
>
>
> Regards,
>
> Richard Broersma Jr.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message lms 2006-11-20 18:28:19 Re: How convert UNICODE
Previous Message Richard Broersma Jr 2006-11-20 17:49:19 Re: How to find out top 3 records in each location