Hey guys, I've picked through as much as the Django docs as possible, but can't seem to find any reference to Sum() allowing any in-method conditionals (i.e. a conditional to Sum() with an in-line IF(), without the use of a WHERE/filter).
The original query in MySQL is: mysql> select SUM(is_spam) as is_spam, SUM(is_image_blocked) as is_image_blocked, SUM(IF(dl_job_state = 2, 1, 0)) as dl_job_success COUNT(*) as total_rows from fourchan_post; +---------+------------------+----------------+------------+ | is_spam | is_image_blocked | dl_job_success | total_rows | +---------+------------------+----------------+------------+ | 9116 | 266516 | 5010939 | 38832166 | +---------+------------------+----------------+------------+ 1 row in set (3 min 13.14 sec) In Django, I'm using (incomplete): >>> Post.objects.aggregate(Count('id'), Sum('is_spam'), Sum('is_image_blocked'), Sum('is_checked')) So far, the only way I can see to do this, would be to do a filter() before the aggregate, but this will affect the other Sum()'s which would mean multiple queries would be necessary. Normally this wouldn't be an issue, but the table has over 40 million rows lol (and it already takes well over 3 minutes to execute) Ideally, I'd like to try and find a way (within the ORM), to specify an IF conditional for the Sum(), thus only having to perform a single query. If this isn't possible, I'll put in a feature request for it. Thanks Cal -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.