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