Skip to content
Advertisement

How to turn 5 sets of data from one column into 5 different columns

My current table looks like this

CPNT_ID Org_Id Stud ID Compl_Dte
Trainee Org001 101010 Nov 13, 2016
SvcTech Org001 101010 Nov 13, 2016
CrewChief Org001 101010 Nov 13, 2016
Trainee Org001 101013 Nov 13, 2016
SvcTech Org001 101013 Nov 13, 2016
Trainee Org002 101011 Nov 13, 2016
SvcTech Org002 101011 Nov 13, 2016
Trainee Org002 101012 Nov 13, 2016

This works if im looking at one organization, but if i need to see multiple organizations I need the table to look like this. I don’t have enough reputation to chat

Organization Trainee SvcTech CrewChief SvcCoord Appr
Org001 2 2 1 0 0
Org002 2 1 0 0 0

This is my code

Advertisement

Answer

You can use case when to pivot the table,and group by in outer layer. SQL code is following:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement