まず、売上合計の結果をt1として保存します
select product, year, sum(sales) as sales
from table
group by 1,2
order by 1,2
次に、crosstab()
を使用しますSELECT *
FROM crosstab(
'SELECT product, year, sales
FROM t1
ORDER BY 1,2')
AS foo("product" text, "2013" int, "2014" int);