减去两个注释列 [英] Subtracting two annotated columns
本文介绍了减去两个注释列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够对两个注释列进行排序。
所以我想做这样的事情:
c = c.annotate(metric = Sum('results__metric'))
c = c.annotate(metric_prior = Sum('results__metric_prior'))
c = c.annotate(variance = F('metric') - F('metric_prior'))#不起作用,仅用于示范目的
然后:
c = c.order_by('variance'有没有人知道如何完成像上面这样的东西?
div class =h2_lin>解决方案
实际上,
c = c.annotate(variance = F('metric') - F('metric_prior')
按照你想要的从Django 1.8开始 。
I need to be able to sort on the aggregate of two annotated columns
So I'd like to do something like this:
c = c.annotate(metric=Sum('results__metric'))
c = c.annotate(metric_prior=Sum('results__metric_prior'))
c = c.annotate(variance=F('metric')-F('metric_prior')) #doesn't work, for demonstrative purposes only
and then:
c = c.order_by('variance')
Does anyone know how to accomplish something like the above?
解决方案
Actually,
c = c.annotate(variance=F('metric')-F('metric_prior'))
works as you would like it to starting with Django 1.8.
这篇关于减去两个注释列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文