0

I need to have a subquery as the FROM clause in django, like so

select a.stuff, b.some_stuff, c.other_stuff from (
  select stuff from table 
  where ...
  group by ...
) as a
left outer join table2 as b on ..
left outer join table3 as c on ..

How can I do this ?

Inspired by This post

The reason I need to do this is for speed, as the obvious table1.objects.values(..).annotate('FkeyB__some_stuff', 'FkeyC__other_stuff') produces group bys after the joins which is slow.

jeffli
  • 1
  • 1

0 Answers0