Re: Select/Group by/Order by question

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

> 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".

Well, I need it grouped by hour, but that led me to the solution:

select to_char(date_trunc('hour',mtrantime),'mm-dd hh AM') as
datetime, count(*) as tot, from memtran
group by mtranoper, date_trunc('hour',mtrantime)
order by mtranoper, date_trunc('hour',mtrantime)

I knew there had to be a straight-forward solution. Thanks Tom.
--
Mike Nolan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hitesh Bagadiya 2004-04-09 08:05:20 Sorting in Unicode not working
Previous Message Tom Lane 2004-04-09 05:48:59 Re: pg_ctl problem