I don’t think that’s currently possible using a pure DQL query, but I’ve written some boilerplate code which can be used in this case.
In that answer I’ve tried to explain how you can build a query, apply some javascript around it (which doesn’t need loads of changes) to produce headings when a column changes value.