Re: Grouping by day, limiting amounts

From: "Woody Woodring" <george(dot)woodring(at)iglass(dot)net>
To: "'A(dot) Kretschmer'" <andreas(dot)kretschmer(at)schollglas(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Grouping by day, limiting amounts
Date: 2006-10-19 14:45:26
Message-ID: 041801c6f38d$37313d70$80b1a8c0@istructure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of A. Kretschmer
Sent: Thursday, October 19, 2006 10:18 AM
To: pgsql-sql(at)postgresql(dot)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(dot)kretschmer(at)schollglas(dot)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(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jim C. Nasby 2006-10-19 16:50:15 Re: [HACKERS] Bug?
Previous Message A. Kretschmer 2006-10-19 14:17:36 Re: Grouping by day, limiting amounts