1

Grade Table is:

create table Grade 
{
grade_letter char(1)
lowerlimit int(20)
upperlimit int(20)
};

insert into Grade (grade_letter, lowerlimit, upperlimit) 
    values (
      ('A', 85, 100),
      ('B', 70,  84),
      ('C', 50,  69),
      ('F',  0,  49));

Suppose some another query returns marks.

Now, I am stuck with the query which takes the grade_letter based on the marks falling in the range given above. I want a query which is not hard-coded and calculates the grade based on the values given in the table only.

1 Answer 1

3

This will do the trick (assuming your marks are in the table Marks):

SELECT      B.grade_letter
FROM        Marks AS A
INNER JOIN  Grade AS B
    ON      A.Mark BETWEEN B.lowerlimit AND B.upperlimit  
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.