Alex Rivera | Logout

Last 12 months, group by week

Asked 2010-09-24T15:11:28.850
21

I have a table with a column REGDATE, a registration date (YYYY-MM-DD HH:MM:SS). I would like to show an histogram (ExtJS) in order to understand in which period of the years users are signing up. I would like to do this for the past twelve months with respect to the current date and to group dates by week.

Any hints?

Edit
Report

1 Answer

23

in MySQL:

SELECT COUNT(*), DATE_FORMAT(regdate, "%X%V") AS regweek FROM table GROUP BY regweek;

or

SELECT COUNT(*), YEARWEEK(NOW(), 2) as regweek FROM table GROUP BY regweek;

in PostgreSQL:

SELECT COUNT(*), EXTRACT(YEAR FROM regdate)::text ||  EXTRACT(WEEK FROM regdate)::text AS regweek FROM table GROUP BY regweek;
answered 2010-09-24T15:14:16.010

Your Answer