Re: Formatting a month in query output

From: Alexander Borkowski <alexander(dot)borkowski(at)abri(dot)une(dot)edu(dot)au>
To: "Rodolfo J(dot) Paiz" <rpaiz(at)simpaticus(dot)com>
Cc: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>, pgsqlnovice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Formatting a month in query output
Date: 2005-01-27 02:03:54
Message-ID: 41F84C0A.1080008@abri.une.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Rodolfo J. Paiz wrote:
> On Thu, 2005-01-27 at 12:31 +1100, Alexander Borkowski wrote:
>
>>Sorry, I totally missed the crucial point there. How about
>>
>>select date_trunc('month', date) as sort_month, to_char(date,'Mon YYYY')
>>as month, count(num) as num, sum(hrs_total) as hours from flights group
>>by sort_month, month order by sort_month asc;
[...]
> This would be perfect if we could get rid of that first column and only
> display the rest. Is that possible?

Apart from just not displaying it on the client side you can do a
subselect. For example:

select to_char(monthly_flights.sort_month, 'Mon YYYY') as month,
monthly_flights.num, monthly_flights.hours
from (

select date_trunc('month', date) as sort_month, count(num) as num,
sum(hrs_total) as hours
from flights group by sort_month

) as monthly_flights
order by monthly_flights.sort_month asc;

Cheers,

Alex

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2005-01-27 05:28:11 Re: Two copies of every mail!
Previous Message Rodolfo J. Paiz 2005-01-27 01:40:09 Re: Formatting a month in query output