select QuestionID,
sum(if(RightSolution=StuSolution,1,0)) as rights,
sum(if(RightSolution<>StuSolution,1,0)) as errors,
sum(if(RightSolution<>StuSolution,1,0))/count(*) as errorPercent,
sum(if(IsExplain=1,1,0)) as reqStuCount
from tt group by QuestionID

解决方案 »

  1.   

    select QuestionID,count(case when rightsolutionn=stusolution then 1 else 0 end) as right,
    count(case when rightsolutionn<>stusolution then 1 else 0 end) as error,
    count(case when rightsolutionn<>stusolution then 1 else 0 end)*100/count(*) as errorPercent,
    count(case when IsExplain=1 then 1 else 0 end) as reqStuCount
    from tb 
    group by QuestionID;