分组查询
Group()
分组查询数据,需要传按哪个字段分组
- @param
field
字段名
Group()
var user []User
err := tg.Db("user").Field("id, max(score)").Group("id").Select(&user)
var user []User
err := tg.Db("user").Field("id, max(score)").Group("id").Select(&user)
最终的SQL语句为:
SELECT id, max(score) FROM user GROUP BY id
SELECT id, max(score) FROM user GROUP BY id