Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Experiment -6

Task to be Done – columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students
who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades
are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those
particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their
name and list them by their grades in descending order
Experiment 6: -
1.First, we have to create a database name exp6

Then we create a new table name Grade

Create database EXP6;

use EXP6;

CREATE TABLE Grades (

Grade INT PRIMARY KEY,

Min_Mark INT,

Max_Mark INT

);

2.Then we put value in table greades

INSERT INTO Grades (Grade, Min_Mark, Max_Mark)

VALUES

(1, 0, 9),
(2, 10, 19),

(3, 20, 29),

(4, 30, 39),

(5, 40, 49),

(6, 50, 59),

(7, 60, 69),

(8, 70, 79),

(9, 80, 89),

(10, 90, 100);

3.we create a new table name student

CREATE TABLE Students (

ID INT PRIMARY KEY,

Name VARCHAR (50),

Marks INT

);
4.Then we put values in that table

INSERT INTO Students (ID, Name, Marks)

VALUES

(1, 'Julia', 88),

(2, 'Samantha', 68),

(3, 'Maria', 99),

(4, 'Scarlet', 78),

(5, 'Ashley Jane', 63),

(6, 'Nameless', 81);

5.we write a query to perform. higher grades are entered first . If there is more than one student with
the
same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally,
if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order
SELECT

CASE

WHEN Grades.Grade >= 8 THEN Students.Name

ELSE 'NULL'

END AS Name,

Grades.Grade,
Students.Marks

FROM Students

LEFT JOIN Grades ON Students.Marks BETWEEN Grades.Min_Mark AND Grades.Max_Mark

WHERE Grades.Grade >= 8

OR Grades.Grade IS NULL

ORDER BY Grades.Grade DESC, Students.Name, Students.Marks;

LEARNING OUTCOMES
We learn that how to write a query with joins and conditions .

We learn that how to write query for printing higher value first then lesser value

We learn that how to write complex query in joins and fetch data according to that.

You might also like