I have a table which is called TrainingMatrix defined as below:
CREATE TABLE TrainingMatrix
(
  "ID" text NOT NULL,
  "TrainingName" text NOT NULL,
  "Institute" text,
  "ExpiryDate" date,
  CONSTRAINT "TrainingMatrix_pkey" PRIMARY KEY ("ID", "TrainingName", "ExpiryDate")
)
Some dummy data is as clarified in the below table:

Editable and testable data can be found here (SQL Fiddle).
I am trying to write SQL statement which can regenerate the table to be as below:

The TrainingName column in the original table TrainingMatrix can take any value, whenever a new value like Tx is added, the second intended table must consider this value as a new column as below:

I am using PostgreSQL 9.2.
 
     
    