Home  >  Q&A  >  body text

django - python 排序时对空值的处理?

我对数据库中的数据进行倒序排序,比如A表中的b列。
select * from A order by b desc
如果b中存在空值,我可以以用nvl处理
如果在python中怎么办呢?
A.object.filter(id=id).order_by(-b)
我怎么处理这个空值呢?有没有类似的给b付空值的方法?请大神帮忙!!

怪我咯怪我咯2713 days ago581

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 11:58:39

    By default, null values ​​will be sorted first. If you have other needs, sorted in Python can specify a sorting function. You can just write a sorting function yourself.

    reply
    0
  • Cancelreply