small medium large xlarge

15 Jan 2014, 10:03
Cuong Thai (1 post)

To build a monthly calendar of events, the query should be

SELECT * FROM crosstab(
  'SELECT extract(year from starts) AS year,
     extract(month from starts) AS month, count(*)
   FROM events GROUP BY year, month ORDER BY year',
  'SELECT * FROM month_count'
) AS (
  year int, jan int, feb int, mar int, apr int, may int,
  jun int, jul int, aug int, sep int, oct int, nov int, dec int

With the query in book, when we add events with different years, we will see many rows with same year.

25 Jan 2014, 07:14
thi ly cuong (3 posts)

that good, let me will try it

You must be logged in to comment