Re: How to find out top 3 records in each location - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: How to find out top 3 records in each location
Date
Msg-id 713709.88122.qm@web31813.mail.mud.yahoo.com
Whole thread Raw
In response to Re: How to find out top 3 records in each location  (Richard Broersma Jr <rabroersma@yahoo.com>)
List 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
> 



pgsql-sql by date:

Previous
From: "lms"
Date:
Subject: Re: How convert UNICODE
Next
From: anil maran
Date:
Subject: LOG: logger shutting down