Skip to content
Advertisement

How to select students with marks in all three subjects less then 100

I came across this question

Here is my response to it, I just started myself learning SQL recently.

Select a.roll_number
     , a.name
     , b.roll_number 
  from student_information a
  join examination_marks b
    on a.roll_number = b.roll_number
 Group 
    by roll_number
 Having Sum(subject_one.examination_marks + subject_two.examination_marks + subject_three.examination_marks) < 100;

Advertisement

Answer

You need not to group by your result since there should be one row in each table for every roll_number. You did the join right. Now just replace group by and having clause with where condition to check whether sum of all three subject’s number is less then 100 or not. If it less then hundred then select roll_number and name.

Select a.roll_number, a.name 
from student_information a
inner join
examination_marks b
       on a.roll_number = b.roll_number
where (subject_one + subject_two + subject_three )< 100;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement