Re: Grouping by date range - Mailing list pgsql-general

From Ron Johnson
Subject Re: Grouping by date range
Date
Msg-id 1061405098.29044.6.camel@haggis
Whole thread Raw
In response to Re: Grouping by date range  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Grouping by date range  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
On Wed, 2003-08-20 at 12:47, Tom Lane wrote:
> Ron Johnson <ron.l.johnson@cox.net> writes:
> > On Tue, 2003-08-19 at 02:56, Alexander Litvinov wrote:
> >> select date_part('year', date), count(*) from your_table group by
> >> date_part('year', date) order by date_part('year', date);
>
> > Is the ORDER BY really needed here?
>
> If you want the results ordered that way, yes.

Hmmmmm.  I don't think so, if the ORDER BY clause is exactly the
same as the GROUP BY clause, which is the case here:
  select date_part('year', date), count(*)
  from your_table
  group by date_part('year', date)
  order by date_part('year', date);

The GROUP BY does implicit sorting, so an ORDER BY on the exact same
column(s) as the GROUP BY is redundant.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"Adventure is a sign of incompetence"
Stephanson, great polar explorer


pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: Mailing list in French
Next
From: Jan Wieck
Date:
Subject: Re: Buglist