Student_id | Skill_id | skill-Score
1 30 5
1 50 1
1 63 2
1 42 2
2 30 7
2 50 3
2 63 6
2 42 9
I am trying to create a table in this format how can i do this.?
Student_id || 30 || 50 || 63 || 42 |
1 5 1 2 2
2 7 3 6 9
here what i have tried but no result please do not consider my try.
SELECT CONCAT(
'SELECT `r_job_scores`.id_score', GROUP_CONCAT('
, `t_', REPLACE(skill_id, '`', '``'), '`.value
AS `', REPLACE(skill_id, '`', '``'), '`'
SEPARATOR ''),
' FROM `r_job_scores` ', GROUP_CONCAT('
LEFT JOIN `r_job_scores` AS `t_', REPLACE(skill_id, '`', '``'), '`
ON `r_job_scores`.id_score = `t_', REPLACE(skill_id, '`', '``'), '`.id_score
AND `t_', REPLACE(skill_id, '`', '``'), '`.skill_id = ', QUOTE(skill_id)
SEPARATOR ''),
' GROUP BY `r_job_scores`.id_score'
)
If the number of skill IDs are known and fixed, then you can use a simple pivot query:
If you want to get a total of student scores, one way to do that would be to subquery the query I gave above and compute the tally: