• It's not really clear what you want, but I think you can put the GROUP BY statement inside the second sub-select (and remove the "q1" alias within this GROUP BY)

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **