How can I group this sql query?

I wonder if this is any help?