0

I have this database called e-classroom with tables :

tbl_enrollment tbl_enrollment

tbl_feenames

tbl_feenames

tbl_feetypes

tbl_feetypes

tbl_payments

tbl_payments

tbl_pupil tbl_pupil

this is the view that I made out from those tables :

view_paylist view_paylist

and I have this MySQL query that will pivot these tables :

 SET @sql = NULL;
 SELECT
 GROUP_CONCAT(DISTINCT
 CONCAT('MAX(IF(vp.cfeename = ''',vp.cfeename,
        ''', vp.nfeetypeamount, NULL)) AS ',
 CONCAT("`",vp.cfeename,"`")
    )
  ) INTO @sql
 FROM view_paylist AS vp;

 SET @sql = CONCAT('SELECT vp.clrn
                , vp.name
                , vp.cgrdlvl
                , csection
                , vp.csy, ', @sql, ' 
               FROM view_paylist vp
 where vp.cgrdlvl like ''%''
 group by vp.clrn
                ');

 PREPARE stmt FROM @sql;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;

and this is the result of the pivot :

pivot

the field "sample" is my newly added data to tbl_feenames. What I want is how can I achieve this dynamic pivoting in PostgreSQL using Crosstab ??

daR
  • 250
  • 2
  • 19

0 Answers0