如果我很好地理解了您的查询,那么可以在不更改数据库结构的情况下这样做:
select MAIN.stu_number, MAIN.stu_name, MAIN.ex_name,
MATHS.stu_score as MATHEMATICS,
ENGLISH.stu_score as ENGLISH,
PHYSICS.stu_score as PHYSICS,
CHEMISTRY.stu_score as CHEMISTRY
from EXAMS_MASTER_REGISTER MAIN
left join EXAMS_MASTER_REGISTER MATHS on MAIN.stu_number = MATHS.stu_number AND MATHS.ex_subject = 'MATHEMATICS'
left join EXAMS_MASTER_REGISTER ENGLISH on MAIN.stu_number = ENGLISH.stu_number AND ENGLISH.ex_subject = 'ENGLISH'
left join EXAMS_MASTER_REGISTER PHYSICS on MAIN.stu_number = PHYSICS.stu_number AND PHYSICS.ex_subject = 'PHYSICS'
left join EXAMS_MASTER_REGISTER CHEMISTRY on MAIN.stu_number = CHEMISTRY.stu_number AND CHEMISTRY.ex_subject = 'CHEMISTRY'
where MAIN.stu_level = '1'
and MAIN.stu_stream = 'EAST'
and MAIN.ex_semester = 'FIRST'
and MAIN.ex_name = 'MIDYEARS'
and MAIN.academic_year = '2012'
order by (NVL(MATHS.stu_score,0) + NVL(ENGLISH.stu_score,0) + NVL(PHYSICS.stu_score,0) + NVL(CHEMISTRY.stu_score,0) ) desc
注意:我更改了顺序,因为在那种形式下它不再可用了,现在这对分数求和,然后按那个排序。
但是,这种确切的数据库结构是不好的。这不是第一范式(1NF),这使事情变得不必要地困难并且容易出错。还可以考虑阅读2NF、3NF和BCNF(其他的也是,但 AFAIK,这些是更广为人知和使用的范式)。我假设您正在学习,这将使您走上正确的轨道。
您应该将一张表分成(至少)两张:一张用于学生的个人数据(现在与 MAIN 别名一起使用的列),一张用于分数(其他列)。