Tuesday, May 13, 2008

Re: [GENERAL] Substring Problem

On Tue, May 13, 2008 at 03:26:57PM +0200, Stefan Schwarzer wrote:
> SELECT substring(date from 1 for 7) AS stryearmonth, COUNT(id) AS
> countofnumber FROM (SELECT * from downloads ) AS foo GROUP BY
> stryearmonth ORDER BY stryearmonth ASC

Another way of doing this is by using date_trunc, i.e.:

SELECT date_trunc('month',date) AS yearmonth...

I think it'll still realise it can use indexes (if they're appropriate)
that way.


Sam

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

No comments: