t.Errorf("no error should happen, but got %v",err)
}
ifname!="groupby"||total!=60{
t.Errorf("name should be groupby, but got %v, total should be 60, but got %v",name,total)
}
iferr:=DB.Model(&User{}).Select("name, sum(age) as total").Where("name LIKE ?","groupby%").Group("name").Having("name = ?","groupby1").Row().Scan(&name,&total);err!=nil{
t.Errorf("no error should happen, but got %v",err)
}
ifname!="groupby1"||total!=660{
t.Errorf("name should be groupby, but got %v, total should be 660, but got %v",name,total)
iferr:=DB.Model(&User{}).Select("name, active, sum(age)").Where("name = ? and active = ?","groupby",true).Group("name").Group("active").Row().Scan(&name,&active,&total);err!=nil{
t.Errorf("no error should happen, but got %v",err)
}
ifname!="groupby"||active!=true||total!=40{
t.Errorf("group by two columns, name %v, age %v, active: %v",name,total,active)