Reputation: 11
I am trying to create a new table by using the dataset in the link below. The return I want to have is like the picture below. Could someone please help?
http://sqlfiddle.com/#!18/766e3/2
Upvotes: 0
Views: 35
Reputation: 1269823
You can use conditional aggregation:
SELECT Employeeid,
SUM(CASE WHEN BusinessUniteID = 1 then Scores END) as score_1,
SUM(CASE WHEN BusinessUniteID = 2 then Scores END) as score_2,
SUM(CASE WHEN BusinessUniteID = 3 then Scores END) as score_3
FROM t_d
GROUP BY EmployeeId;
This assumes that you know what all the business unit ids are.
Here is a db<>fiddle.
Upvotes: 1