I am stuck to create dynamic column from select query,
Name ID ROLE_START ROLE DEPT
Peter 271 2016-04-15 Jr. Developer Dev
Peter 271 2015-10-13 Trainee Dev
Thomas 596 2019-05-20 Jr. Tester Testing
Thomas 596 2019-02-18 Trainee Testing
Ablish 070 2011-05-02 Artist Designer
Adarsh 429 2018-04-01 Jr. Data Scientist Data
Adarsh 429 2018-06-01 Data Scientist Data
My Required out put is,
Name ID 201105_ROLE 201105_DEPT 201510_ROLE 201510_DEPT 201604_ROLE 201604_DEPT 201902_ROLE 201902_DEPT
Peter 271 Trainee Dev Jr. Developer Dev
Thomas 596 Trainee Testing Jr. Tester Testing
... ...
etc
my query was,
select
emp_id,
nickName,
if(SUBSTRING_INDEX(SUBSTRING_INDEX(comp_roles, '200801:', -1), ',', 1) like "20%", null, SUBSTRING_INDEX(SUBSTRING_INDEX(comp_roles, '200801:', -1), ',', 1)) as `200801`,
...
from employee e
join role_data rd on rd.empID = r.empID
group by r.empID
is they any better method to do so?