Re: Select/Group by/Order by question - Mailing list pgsql-general

From Tom Lane
Subject Re: Select/Group by/Order by question
Date
Msg-id 21483.1081489477@sss.pgh.pa.us
Whole thread Raw
In response to Select/Group by/Order by question  (Mike Nolan <nolan@gw.tssi.com>)
Responses Re: Select/Group by/Order by question
List pgsql-general
Mike Nolan <nolan@gw.tssi.com> writes:
>    select  to_char(mtrantime,'mm-dd hh AM') as datetime,
>    count(*) as tot from memtran
>    group by datetime
>    order by datetime;
> The problem is this produces the data in the following order:
> ...
> What I'd really like is to get it in chronological order by hour:

You are grouping/ordering by the textual result of to_char(),
in which PM naturally follows AM.  I think the behavior you
want would come from grouping/ordering by the underlying
timestamp column "mtrantime".

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Upgrading from 7.3.6 to 7.4.2 pg_dumpall question
Next
From: Tom Lane
Date:
Subject: Re: pg_ctl problem