I have a query that recreates the row names into column names on the second query. Ideally will have two queries by using temporary tables are implementation. I have the first query like this:
select * from scores;
Giving me this result
EmpID Class Amount
1 First 200
1 Second 300
1 Third 400
Desired results:
EmpID First Second Third
1 200 300 400
Query tried so far
select EmpID,
(case when p.DeductionName like '%First' then Amount else null end) as First,
(case when p.DeductionName like '%Second' then Amount else null end) as Second,
(case when p.DeductionName like '%Third' then Amount else null end) as Third
from scores;
This one gives such a result
EmpID First Second Third
1 200 null null
1 null 300 null
1 null null 400
Am now struggling on how I can get the desired output i.e.
EmpID First Second Third
1 200 300 400