使用一个切片来填充 ?
的位置,不需要括号,遇到切片的变量,gorm会自动补全一对括号。
var sons []string
var score []DepartScore
......
db.Debug().Raw("select avg(score) as score, min(updatetime) as time from xxx where activity_id = ? and departid in ?", activityId, sons).Scan(&score)
虽然自己加了括号也不影响,但是对于复杂的SQL,例如有子查询的,gorm就不检测了,你会发现有两对括号,报错。