Py学习  »  问与答

django的group by,好烦

juma • 9 年前 • 3667 次点击  

找了一圈group by的东西。没有解决我的需求: 问题: select id,max(price) ,groupid from table where vote>1 group by groupid 如果使用 .objects.filter(条件).value(price).annatate(max(price)) 的方法, 那么id 和 groupid 这两个字段,无法显示。 有什么好的方法么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1238
 
3667 次点击  
文章 [ 1 ]  |  最新文章 9 年前
MCC
Reply   •   1 楼
MCC    9 年前

我以前写过这样的东西,不知道能不能用上

 subject_category_raws = Discovery.objects.values(
        'subject',
        'subject__name',
        'category',
        'category__name').order_by(
        'subject',
        'category').annotate(ccount=Count('category'))