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