Maybe, you can use dynamic component extension+schema and do a for each loop. Here on the forum there is the guide to create Schema.
So each record returned from select SQL will generate a layout ( Json schema) You create the schema Uses the Dynamics Components + Json Schema extension. The loop will generate N times the layout that the schema generates.
Hugs