I have these fields in MySQL:
rpt_id, rpt_entrydate, rpt_exitdate, rpt_date
and the values of these fields are as follows:
1, 2012-11-02, 2012-11-03, 2011-11-26
2, 2011-11-23, 2012-11-16, 2011-11-26
3, 2011-11-25, 2012-11-26, 2011-11-26
4, 2011-10-14, 2012-10-17, 2011-10-13
5, 2011-10-05, 2012-10-09, 2011-10-13
6, 2011-10-15, 2012-10-18, 2011-10-13
I want my result to look like this but it doesn’t work:
2011-11-25, 2012-11-26, 2011-11-23, 2012-11-16, 2012-11-02, 2012-11-03, 2011-11-26
2011-10-15, 2012-10-18, 2011-10-05, 2012-10-09, 2011-10-14, 2012-10-17, 2011-10-13
It appears you are attempting to string together all the dates associated with each
rpt_dateby group. You can do this with aGROUP_CONCAT()and a couple ofCONCAT_WS()concatenations.The inner
CONCAT_WS()combines the pair ofrpt_entrydate, rpt_exitdateinto a comma-separated string, and the outerCONCAT_WS()pairs theGROUP_CONCAT()string with itsrpt_dategroup.http://sqlfiddle.com/#!2/9a07a/5