美文网首页
aggregation other things

aggregation other things

作者: xncode | 来源:发表于2017-09-12 14:50 被阅读0次

filter

在filter之后的是会在过滤后的结果上进行聚合操作,在annotate之后也是可以进行filter的。

Book.objects.filter(name__startswith="Django").annotate(Count('author')
Book.objects.filter(name__startswith="Django").aggregate(Avg('price'))
Book.objects.annotate(num_authors=Count('authors')).filter(num_authors__gt=1)

order by

annotation可以作为排序的依据

values

之前所述,annotation是给匹配到的每行产生一个值
当使用values时,则是会按照给定values字段组合,annotation是对应group的。

group by

注意,values在annotate之前才能完成该操作,否则还是在产生了annotation之后再拿到values。

相关文章

网友评论

      本文标题:aggregation other things

      本文链接:https://www.haomeiwen.com/subject/tfhcsxtx.html