Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active December 19, 2015 09:19
Show Gist options
  • Save yancya/5932058 to your computer and use it in GitHub Desktop.
Save yancya/5932058 to your computer and use it in GitHub Desktop.
PostgreSQL の crosstab サンプル
-- PostgreSQL 9.2 で動作確認
create extension tablefunc
;
select *
from crosstab('
select year, month, 5
from generate_series(2009, 2013) as year
cross join generate_series(1, 12) as month', '
select generate_series(1, 12)')
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)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment