golang gorm 怎么得到sum()值?

LongingWorld · · 7542 次点击
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
更多评论
我感觉是你没有对应好值,SUM(a.fraction) as totalScore,
#1
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