求和数据可以使用Sum, SumInt, Sums 和 SumsInt 四个方法,Sums系列方法的参数为struct的指针并且成为查询条件。
Sum
SumInt
Sums
SumsInt
type SumStruct struct { Id int64 Money int Rate float32 } ss := new(SumStruct) total, err := engine.Where("id >?", 1).Sum(ss, "money") fmt.Printf("money is %d", int(total))
type SumStruct struct { Id int64 Money int Rate float32 } ss := new(SumStruct) total, err := engine.Where("id >?", 1).SumInt(ss, "money") fmt.Printf("money is %d", total)
ss := new(SumStruct) totals, err := engine.Where("id >?", 1).Sums(ss, "money", "rate") fmt.Printf("money is %d, rate is %.2f", int(total[0]), total[1])
ss := new(SumStruct) totals, err := engine.Where("id >?", 1).SumsInt(ss, "money") fmt.Printf("money is %d", total[0])
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8