![image.png](https://static.studygolang.com/180716/615352954c07341b595ebd3793cd4424.png)
![image.png](https://static.studygolang.com/180716/c8ca91ebc90f718a9e01e647ecea32a0.png)
这两种得到的都是零,请大神指点,初次使用GORM
var totalScore []int
db.Table("xy_subject_answer a"). /* Select("SUM(a.fraction) as totalScore"). */
Joins("left join xy_staff_auswer_option b on (a.id = b.subject_answer_id)").
Where("b.staff_answer_id = ?", 282).Pluck("SUM(a.fraction)", &totalScore)
我按你的这么写了,还是不行,最终用的上面的这段,得到了正确的结果
#2
更多评论
var totalScore []int db.Table("xy_subject_answer a"). / Select("SUM(a.fraction) as totalScore"). / Joins("left join xy_staff_auswer_option b on (a.id = b.subject_answer_id)"). Where("b.staff_answer_id = ?", 282).Pluck("SUM(a.fraction)", &totalScore)
我按你的这么写了,还是不行,最终用的上面的这段,得到了正确的结果
#3