Re: Group by date

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Group by date
Date: 2001-08-23 00:57:32
Message-ID: 9m1kdr$peg$1@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 21 Aug 2001 23:10:08 -0700, Dale Emmons <dale(at)emmons(dot)com> wrote:
> Hello!
>
> I'm trying to be a convert from mysql, which I feel quite comfortable with.
>
> In mysql I can do the following:
>
> CREATE TEMP TABLE hits (
> datetime TIMESTAMP
> );
>
> Fill it with some data, and then do this:
>
> SELECT datetime, COUNT(*)
> FROM hits
> GROUP BY DATE(datetime)
>
> When I try that in PostgreSQL I get this error when I try the above query:
> Attribute hits.datetime must be GROUPed or used in an aggregate function
>
> The query works fine in mysql, why not postgres?
>

Try this:

SELECT DATE(datetime), count(*)
FROM hits
GROUP BY DATE(datetime);

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2001-08-23 01:01:10 Re: SELECT FOR UPDATE
Previous Message Oberpriller, Wade D. 2001-08-22 23:21:29 FW: Re: Dynamically discovering field names in PLPGSQL queries