Skip to content

排序


Order()

对查询结果进行排序,需要传两个参数

  • @param field 排序的字段
  • @param sort 排序规则,DESC倒序 ASC正序,默认倒叙

Order()

var user []User
err := tg.Db("user").Where("age", ">", 10).Group("age").Order().Select(&user)
var user []User
err := tg.Db("user").Where("age", ">", 10).Group("age").Order().Select(&user)

最终的SQL语句为:

SELECT * FROM user WHERE age > 10 ORDER BY age DESC
SELECT * FROM user WHERE age > 10 ORDER BY age DESC

备案号:冀ICP备20015584号-5