Creating a table from a query

I think you may me looking for dynamic columns: