使用以下语句:
id []int64
type Score struct {
Score int `gorm:"score"`
}
func GetScoreByID(score *Score, id []int64) error {
db.Table("question_bank").Select("sum(score) as score").Where("id IN ?", id).Scan(&score).Error
}
报告以下错误:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?)' at line 1
我该如何编写才能实现此功能?
只需将函数参数score *Score
更改为score *int64
,因为score是指针,所以不需要将&
放在Scan
中的score之前。
func GetScoreByID(score *int64, id []int64) error {
return db.Table("question_bank").
Select("sum(score)").
Where("id IN ?", id).
Scan(score).Error
}