I have this table:
Id name degree
1 Ahmad BS
2 John MA
3 Abed MA
4 Sami DR
5 Mona BS
6 Sara BS
I want to split names based on degree so that the degree will be the header and any empty value in column will fill it with NULL
and the names in column will be sorted by Apathetically.
the result should be:
BS MA DR
Ahmad Abed Sami
Mona John NULL
Sara NULL NULL
What I tried:
SELECT
GROUP_CONCAT(if(degree = 'BS', name, NULL)) AS 'BS',
GROUP_CONCAT(if(degree = 'MA', name, NULL)) AS 'MA',
GROUP_CONCAT(if(degree = 'DR', name, NULL)) AS 'DR'
FROM persons
GROUP BY name;
But it seems not correct.