Creating Pivot Tables in PostgreSQL Using the Crosstab Function
SELECT*FROMcrosstab('select extract(month from period)::text, subject.name,trunc(avg(evaluation_result),2)from evaluation, subjectwhere evaluation.subject_id = subject.subject_id and student_id = 1group by 1,2 order by 1,2')ASfinal_result(MonthTEXT, GeographyNUMERIC,HistoryNUMERIC,LanguageNUMERIC,MathsNUMERIC,MusicNUMERIC);
source:
$link[host]
Read Original Source