From: Woody Woodring <george.woodring@iglass.net>
To: 'A. Kretschmer' <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: Grouping by day, limiting amounts
Date: Thu, 19 Oct 2006 10:45:26 -0400
Message-ID: <041801c6f38d$37313d70$80b1a8c0@istructure.com> (raw)
In-Reply-To: <20061019141736.GD10803@a-kretschmer.de>
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.org so that your
message can get through to the mailing list cleanly
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: george.woodring@iglass.net, andreas.kretschmer@schollglas.com
Subject: Re: Grouping by day, limiting amounts
In-Reply-To: <041801c6f38d$37313d70$80b1a8c0@istructure.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