I came into this thread late, so I don't know what you schema looks like.
I have a table that has a timestamp with time zone field and other data. I
can write a query that give me a count per day
SELECT count(*) AS count, date_trunc( 'day', hour) AS day FROM
hist_callhealth GROUP BY day;
This will give me a count per day, to get the top X
SELECT count, day FROM (SELECT count(*) AS count, date_trunc( 'day', hour)
AS day FROM hist_callhealth GROUP BY day) AS foo ORDER BY count desc limit
X;
Hope this helps,
Woody
IGLASS Networks
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of A. Kretschmer
Sent: Thursday, October 19, 2006 10:18 AM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Grouping by day, limiting amounts
am Thu, dem 19.10.2006, um 6:55:41 -0700 mailte chester c young folgendes:
> --- "A. Kretschmer" <andreas.kretschmer@schollglas.com> wrote:
>
> > > I would like to select the 3 (or 10) names with the most votes for
> > each day.
> > >
> > > Any suggestions on how can it be done easily?
>
> Am I misunderstanding, or can you write a simple:
>
> select * from <table> where <date>='2006-10-10'
> limit 5 order by <vote_ct> desc;
>From the first mail:
"I would like to select the 3 (or 10) names with the most votes for each
day."
_FOR_ _EACH_ _DAY_.
Your query returns the values only for one day...
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to
majordomo@postgresql.orgso that your message can get through to the mailing list cleanly