SELECT * FROM crosstab(
'SELECT cola, EXTRACT(HOUR from colb) AS h, count(*) AS ct
FROM fooo
GROUP BY 1, 2
ORDER BY 1, 2'
,'SELECT g::float8 FROM generate_series(0,23) g'
) AS ct (cola text
, h00 int, h01 int, h02 int, h03 int, h04 int, h05 int
, h06 int, h07 int, h08 int, h09 int, h10 int, h11 int
, h12 int, h13 int, h14 int, h15 int, h16 int, h17 int
, h18 int, h19 int, h20 int, h21 int, h22 int, h23 int);
Asides:
Zapomněli jste na hodinu 0 / 24.
Použití názvů sloupců s úvodním znakem, abyste se vyhnuli nutnosti dvojitých uvozovek.
Podrobnosti: