SELECT * FROM (
select student_id, class_id,
sum(number*(1-abs(sign(subject-1)))) as sub1,
sum(number*(1-abs(sign(subject-2)))) as sub2,
sum(number*(1-abs(sign(subject-3)))) as sub3,
sum(number*(1-abs(sign(subject-4)))) as sub4,
sum(number*(1-abs(sign(subject-5)))) as sub5,
sum(number*(1-abs(sign(subject-6)))) as sub6
from result GROUP BY student_id,class_id) m
where class_id = '7'
它的查询工作正常。但如果主题值为空,则所有学生记录都不会显示在该主题中。我需要再发烧一次。