how to generate view data from sql query?
It looks like you're selecting 30 nodes of type 'post' and grouping them by user.  This view would be pretty easily built using the views UI. Once you've created the view, you should be able to add an author uid as a grouping field.  This will group the post fields by author.

Let me know if you have questions.