Re: Select/Group by/Order by question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Re: Select/Group by/Order by question
Date: 2004-04-09 05:44:37
Message-ID: 21483.1081489477@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Nolan <nolan(at)gw(dot)tssi(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-04-09 05:48:59 Re: pg_ctl problem
Previous Message Tom Lane 2004-04-09 05:22:32 Re: Upgrading from 7.3.6 to 7.4.2 pg_dumpall question