I am new to postgresql and even newer to crosstab but from what I have read, the below query should work:
select * from crosstab(
$$select distinct "AccountNumber" , "ProductCategory", sum("ProductQuantity") sm
from "MsfDataRecords" mdr
group by "ProductCategory", "AccountNumber", "ProductQuantity"$$
)as ct("AccountNumber" text , "ProductCategory" text , sm numeric)
But this errors with SQL Error [42601]: ERROR: return and sql tuple descriptions are incompatible
I have checked all the data types and they are correct. I'm not sure if it is to do with the sum function though.
Any help appreciated