That seems very complex. Have you considered renaming the columns like:
SELECT ‘a’ as ‘D1_a’, ‘a2’ as ‘D2_a’
It would eliminate the need for the sub-heading. It’s not as pretty but still functional.