Sum
Sum methods
You can use Sum
, SumInt
, Sums
and SumsInt
methods to summerize columns, and you can also use sql conditions and struct conditions.
- Sum
type SumStruct struct {
Id int64
Money int
Rate float32
}
ss := new(SumStruct)
var err error
var total float64
total, err = engine.Where("id >?", 1).Sum(ss, "money")
fmt.Printf("money is %d", int(total))
- SumInt
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)
- Sums
ss := new(SumStruct)
var err error
var totals []float64
totals, err = engine.Where("id >?", 1).Sums(ss, "money", "rate")
fmt.Printf("money is %d, rate is %.2f", int(total[0]), total[1])
- SumsInt
ss := new(SumStruct)
var err error
var totals []int64
totals, err = engine.Where("id >?", 1).SumsInt(ss, "money")
fmt.Printf("money is %d", total[0])