Re: "How do I ..." SQL question

Поиск
Список
Период
Сортировка
От PFC
Тема Re: "How do I ..." SQL question
Дата
Msg-id opskruwbvwth1vuj@musicbox
обсуждение исходный текст
Ответ на "How do I ..." SQL question  (zeus@ix.netcom.com)
Ответы Re: "How do I ..." SQL question  ("Bob" <BHockney@ix.netcom.com>)
Список pgsql-sql
  Return only four rows beginning at second row:
>
> SELECT count(*) AS count, name, year FROM a
>   GROUP BY name, year
>   ORDER BY count DESC, name ASC
>   LIMIT 4 OFFSET 1;
>
>  count   name   year
> ------- ------ ------
>    3     joe    2004 s,e,e
>    2     bob    2003 w,e
>    2     kim    2003 s,s
>    2     sue    2004 s,w
>
> Select only places visited included in LIMITed query:

Is this :
SELECT DISTINCT place FROM a,(
SELECT count(*) AS count, name, year FROM a   GROUP BY name, year   ORDER BY count DESC, name ASC   LIMIT 4 OFFSET 1
) as foo WHERE name=foo.name AND year=foo.year
Problem with this approach is that you'll have to run the query twice,  
one to get the hitlist by user, one for the places...

>
> SELECT DISTINCT place FROM a ????;
>
>  place
> -------
>  south
>  west
>  east
>
> Note that the place north does not appear in the last result
> because north was only visited by bob in 2005 and kim in 2004,
> records which are not included in the limited result.
>
> Any help appreciated.
>
> -Bob
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>




В списке pgsql-sql по дате отправления:

Предыдущее
От: zeus@ix.netcom.com
Дата:
Сообщение: "How do I ..." SQL question
Следующее
От: Achilleus Mantzios
Дата:
Сообщение: mail + rfc822, rfc2822 + schema