Skip to content

Instantly share code, notes, and snippets.

@haeric
Last active December 22, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haeric/6430547 to your computer and use it in GitHub Desktop.
Save haeric/6430547 to your computer and use it in GitHub Desktop.
annotated_self = Showing.objects.filter(pk=8).annotate( num=Sum('billig_showing__ticket_groups__num'), num_sold=Sum('billig_showing__ticket_groups__num_sold') )
SELECT "event_showing"."id", "event_showing"."event_id", "event_showing"."billig_showing_id",
"event_showing"."uka_showing_id", "event_showing"."publish_time", "event_showing"."place",
"event_showing"."free", "event_showing"."canceled", "event_showing"."entrance_id",
SUM("billig_ticket_group"."num") AS "num",
SUM("billig_ticket_group"."num_sold") AS "num_sold"
FROM "event_showing"
LEFT OUTER JOIN "billig_event" ON ("event_showing"."billig_showing_id" = "billig_event"."event")
LEFT OUTER JOIN "event_ukashowing" ON ("event_showing"."uka_showing_id" = "event_ukashowing"."id")
LEFT OUTER JOIN "billig_ticket_group" ON ("billig_event"."event" = "billig_ticket_group"."event")
WHERE "event_showing"."id" = 8
GROUP BY "event_showing"."id", "event_showing"."event_id", "event_showing"."billig_showing_id", "event_showing"."uka_showing_id", "event_showing"."publish_time", "event_showing"."place", "event_showing"."free", "event_showing"."canceled", "event_showing"."entrance_id", "billig_event"."event_time", "event_ukashowing"."date"
ORDER BY "billig_event"."event_time" ASC, "event_ukashowing"."date" ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment