Let's say I have selected records like this
+----+-------------------------------------------------------------------------------------
| id | groupedStatus |
+----+-------------------------------------------------------------------------------------
| 1 | received,accepted,discarded,discarded,accepted,discarded,accepted,received,received |
| 2 | accepted,discarded,received,received,received,received,received |
+----+-------------------------------------------------------------------------------------
Along with the above records, I also want to get the occurrence of each substring in the groupedStatus string,
for example, in the first row, the occurrences are as follows:
received: 3 accepted: 3 discarded: 3
Original Table Schema
Table1
ID int
Table 2:
ID
Table1ID
Status enum('received','accepted','discarded')
I am selecting above records using the following query
select t1.id, group_concat(t2.status) as groupedStatus from Table1 t1 inner join Table2 t2 on t1.id=t2.table1ID group by t1.id