Mike Mike -4 years ago 96
SQL Question

How can I select data from multiple SQL tables?

I have 2 tables, as described below:


student id,


student id,

I want to display the names of students, their average on the 3 exams, and a letter grade. The letter grade is computed as follows:

90+ is an “A”
80 - <90 will be a “B”
, and so on. How should i do it.?

Answer Source
> SELECT n.student_names, ((g.exam1+g.exam2+g.exam3)/3) AS 'AVERAGE_RESULT', (CASE 
              WHEN ((g.exam1+g.exam2+g.exam3)/3) =90  
                 THEN 'A' 
              WHEN (((g.exam1+g.exam2+g.exam3)/3) BETWEEN 80 AND 89)  
                 THEN 'B' 
              WHEN (((g.exam1+g.exam2+g.exam3)/3) BETWEEN 70 AND 79)  
                 THEN 'C' 
              ELSE 'D') END AS 'Student_grades',
FROM names n, grades g
WHERE n.students_id = g.students_id;

Using BETWEEN to include the ranges

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download