Hi Abdess,
You dont have to write a custom query for using Grouyp by function in BO designer.
You can create a measure object as Count(object_id) in universe.
In the report, what ever dimensions you are selecting along with this measure will be grouped by automatically.
You also have an option of creating derive table to create your custom query.
For you above requirement you can just drag all the objects in the query and can set the query property as 'do not retrieve duplicate rows'
Thanks