开发者

django group by another field

开发者 https://www.devze.com 2023-03-08 23:52 出处:网络
Hey, I want to make a query that will give me the same as this in SQL: select testresult.*,max(timeEnd)

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

精彩评论

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