Primary key requirement in raw SQL complicates the query in Django

后端 未结 4 964
醉酒成梦
醉酒成梦 2021-01-05 16:52

To get max value from a simple table of values, I can write the following query in Django:

MyTable.objects.aggregate(Max(\'value\'))

The SQ

4条回答
  •  广开言路
    2021-01-05 17:40

    I would do something like:

    select id, value from mytable order by value desc limit 1
    

提交回复
热议问题