1.需要动态传参:
for (VideoPrizeQuestion videoPrizeQuestion : videoPrizeInfo.getQuestionItems()) {
num++;
rightAnswer = videoPrizeQuestion.getAnswer();
//查询每道题答对的正确率
int ratio = videoQAMapper.selectRatio(videoPrizeQuestion.getVpKey(), num, rightAnswer);
videoPrizeQuestion.setRatio(ratio + "%");
}
2. mapper文件
Integer selectRatio(@Param("key") Long key, @Param("num") Integer num, @Param("rightAnswer") Integer rightAnswer);
3.sql语句
select ifnull(ROUND((select count(1) from
hotkidclub_campaign.video_prize_giving_memberrecord
where `vpKey` = #{key} and question_#{num} = #{rightAnswer})*100/count(1),2),0)
from
hotkidclub_campaign.video_prize_giving_memberrecord
where `vpKey` = #{key}