I have three tables in my database that I want to merge them and display them using crosstab
function, please check this picture :
So what I'vre tried to do, by following this answer, is to join these three tables in one view and then use crosstab
on it like this:
create or replace view t as
SELECT a.code as code_an, n.code as code_n, montant
FROM analytic a JOIN analytic_has_nature ON (a.id = id_analytic)
JOIN nature n ON (n.id = id_nature);
SELECT *
FROM crosstab(
'SELECT code_an, code_n, montant
FROM t
ORDER BY 1,2')
AS t2 (code_an character varying(50), code_n character varying(50), montant double precision);
unfortunately, Postgresql shows me this error:
ERREUR: return and sql tuple descriptions are incompatible
What am I missing ?