orderby (order by, desc and other sorting options)

[edit|delete]

Given

 db=SQLDB(....)
 db.define_table('mytable',SQLField('myfield'),SQLField('datefield','date'))

You can order ascending:

 db().select(orderby=db.mytable.myfield)

Order descending:

 db().select(orderby=~db.mytable.myfield)

Combine ordering rules:

 db().select(orderby=~db.mytable.myfield|db.mytable.datefield)

You can also do

  db().select(orderby="mytable.myfield DESC")

where "..." is an SQL orderby option, and things like

  orderby=db.mytable.myfield.upper()
  orderby=db.mytable.datefield.month()

or combinations of any of the above.



Post a comment