I am trying to implement a Pivot Table (Cross Tab query) for showing attendance details of an employee. I managed this by following query.
SELECT id,name,
GROUP_CONCAT(if(date = '2015-04-01', atten, NULL)) AS '2015-04-01',
GROUP_CONCAT(if(date = '2015-04-02', atten, NULL)) AS '2015-04-02',
GROUP_CONCAT(if(date = '2015-04-03', atten, NULL)) AS '2015-04-03',
GROUP_CONCAT(if(date = '2015-04-04', atten, NULL)) AS '2015-04-04',
GROUP_CONCAT(if(date = '2015-04-05', atten, NULL)) AS '2015-04-05'
FROM tbl
GROUP BY id;
I used this code in my procedure, now i don't want to write group_concat multiple times, and it is dynamic, and changes every time.
So I want to loop group_concat , if possible.
Please See this - http://sqlfiddle.com/#!9/b30e2/1
Thanks in Advance.