Mike Mike - 1 month ago 11
SQL Question

How can I select data from multiple SQL tables?

I have 2 tables, as described below:

Grades

student id,
exem1,
exam2,
exam3


Names

student id,
names


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
> 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