I am trying to find a way to do pivot in Postgres but I can’t use it and I am trying to find another way. I found the following website that explains pivot in SQL Server and in example one is what exactly I want to do. http://sqlhints.com/2014/03/10/pivot-and-unpivot-in-sql-server/
The example is:
CREATE TABLE CourseSales(Course VARCHAR(50),Year INT,Earning MONEY);
INSERT INTO CourseSales VALUES('.NET',2012,10000);
INSERT INTO CourseSales VALUES('Java',2012,20000);
INSERT INTO CourseSales VALUES('.NET',2012,5000);
INSERT INTO CourseSales VALUES('.NET',2013,48000);
INSERT INTO CourseSales VALUES('Java',2013,30000);
With the pivot function the query is the following:
SELECT *FROM CourseSales
PIVOT(SUM(Earning)
FOR Course IN ([.NET], Java)) AS PVTTable;
I would like to do the same in postgresql but with a dynamic way like the above.