开发者

django group by another field

Hey, I want to make a query that will give me the same as this in SQL:

select testresult.*,max(timeEnd) 
from testresult 
group by testres开发者_如何学Goult.idTest

idTest is not PK in testresult. it is FK in test

the need is for the maximal testresult for any test let's say

s=query()
s[0].id       ;is that TestResult


You can group by any field, not only by primary key.

TestResult.objects.values('idTest').annotate(max_time_end=Max('timeEnd')).order_by()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜