I have a query:
SELECT
count(session_id_open) as opens,
count(session_id_visit) as visits,
date_intervals_open,
group_concat(date_intervals_visit)
FROM
bla
GROUP BY date_intervals_open
I get following table. What I need is to find percentage wise the occurrences of each value appearing in group_concat. So, basically, I need to count number of values (date_intervals_visit) in each group (data_intervals_open)
opens visits date_intervals_open group_concat
213 5 day (12-16) evening (17-21),evening (17-21),day (12-16),day (12-16),day (12-16)
113 0 evening (17-21) NULL
11 0 late evening (22-00) NULL
396 12 morning (5-11) morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11),morning (5-11)
9 0 night (1-4) NULL
That is approximately the table that I need to get. in First record evening has 40 because "evening (17-21)" appears twice and the number of all occurrences is 5. 2/5*100=40
opens visits date_intervals_open evening(17-21) day(12-16) morning (5-11)
213 5 day (12-16) 40 60 0
113 0 evening (17-21) NULL NULL NULL
11 0 late evening (22-00) NULL NULL NULL
396 12 morning (5-11) 0 0 100
9 0 night (1-4) NULL
PS: I used group_concat just to visualize the value that I have there. I do not have to use it as it will be an additional effort to parse it afterwards.