I have an sql query that is returning 12 columns with the percentage data. I would like to transpose the query to have 12 rows in one column and the % data in another column
What I have:
What I would like:
Tha nks
I have an sql query that is returning 12 columns with the percentage data. I would like to transpose the query to have 12 rows in one column and the % data in another column
What I have:
What I would like:
Tha nks
If your DBMS supports the UNPIVOT function, you could try this.
SELECT Proposal_source, [%]
from (select candidate_generator,
crm_srt_ui,
knock_on_effect,
matchmaker_mutator,
ml_models,
object_association,
script_manual_data,
unified_onboarding
from tableA) p
UNPIVOT
( [%] FOR Proposal_source in
(candidate_generator,
crm_srt_ui,
knock_on_effect,
matchmaker_mutator,
ml_models,
object_association,
script_manual_data,
unified_onboarding )
) as unpvt;
If it does not support UNPIVOT, Then you could try union all the columns together
SELECT 'unified_onboarding' as Proposal_source, unified_onboarding as '%' FROM tableA
UNION
SELECT 'script_manual_data' as Proposal_source, script_manual_data as '%' FROM tableA
UNION
SELECT 'matchmaker_mutator' as Proposal_source, matchmaker_mutator as '%' FROM tableA
UNION
SELECT 'ml_models' as Proposal_source, ml_models as '%' FROM tableA
UNION
SELECT 'candidate_generator' as Proposal_source, candidate_generator as '%' FROM tableA
UNION
SELECT 'knock_on_effect' as Proposal_source, knock_on_effect as '%' FROM tableA
UNION
SELECT 'crm_srt_ui' as Proposal_source, crm_srt_ui as '%' FROM tableA
UNION
SELECT 'object_association' as Proposal_source, object_association as '%' FROM tableA