I have a MySQL query which provides the following result,

The query used is
SELECT modi, aid FROM (SELECT
GROUP_CONCAT(id) his,
an_id aid,
GROUP_CONCAT(m_id) modi
FROM
ah
GROUP BY an_id, m_id) t1
GROUP BY aid, modi
order by aid;
Now I need a MySQLquery which will give me a result set where if columnaidhas the same value in two rows should create a new column with sameaidandmodi`.
For example, the first two rows in the image as same aid but different modi. The result I need should have 3 column and the row should look like,
aid modi modi2
27 6,6,6,6,6,6,6,6,6 8
I am very new to SQL. Thanks in advance