Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- squirrel_table
- - name
- - country_of_origin
- - id
- nut_table
- - id
- - squirrel_who_owns_me[fk to squirrel]
- select sq.*,
- nut_counts.nut_count
- from squirrel_table sq,
- (select sq2.id as squirrel_id,
- count(nuts) as nut_count
- from squirrel_table sq2,
- nut_table nuts
- where nuts.squirrel_who_owns_me = sq2.id
- and sq.country_of_origin = 'USA'
- group by sq2.id) as nut_counts
- where sq.id = nut_counts.squirrel_id
- sql = 'select sq.id as pk, sq.* ... %s'
- squirreled = squirrel_table.objects.raw(sql, ["arg1"])
Add Comment
Please, Sign In to add comment