As far as I know, reasonable SQL engines require that every selected
column is either in GROUP BY, or wrapped in an aggregation function
(and on those that don't enforce this rule, the result contains
arbitrary values). I fail to see how a query like this could map to
model instances.
Perhaps if you could provide a more specific example of what kind of
query you're trying to build here?
Merely based on your vague description, it seems to me that this is
one of the cases where you might be better off writing your SQL query
manually.
Cheers,
Michal