From: Richard Broersma Jr <rabroersma@yahoo.com>
To: Richard Broersma Jr <rabroersma@yahoo.com>
To: wen tseng <went@hteamericas.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to find out top 3 records in each location
Date: Mon, 20 Nov 2006 09:57:41 -0800 (PST)
Message-ID: <713709.88122.qm@web31813.mail.mud.yahoo.com> (raw)
In-Reply-To: <452822.24102.qm@web31801.mail.mud.yahoo.com>
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
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rabroersma@yahoo.com, went@hteamericas.com
Subject: Re: How to find out top 3 records in each location
In-Reply-To: <713709.88122.qm@web31813.mail.mud.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox