johanntagle

postgresql crosstab

May 7th, 2019
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select * from crosstab(
  2. 'select extract(year from starts) as year,
  3. extract(month from starts) as month,
  4. count(*)
  5. from events
  6. group by year, month
  7. order by year, month',
  8. 'select * from month_count'
  9. ) as (
  10. year int,
  11. jan int, feb int, mar int, apr int, may int, jun int,
  12. jul int, aug int, sep int, oct int, nov int, dec int
  13. ) order by year;
Advertisement