Skip to content

Commit 4d2bd11

Browse files
Update SQL_Class_4.txt
1 parent 43ba63f commit 4d2bd11

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

SQL_Class_4.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,43 @@ create table customer_order_data
7373
cust_country varchar(50)
7474
);
7575

76+
77+
# Case When in SQL
78+
Create table student_marks
79+
(
80+
stu_id int,
81+
stu_name varchar(50),
82+
total_marks int
83+
);
84+
85+
insert into student_marks values(1,'Shashank',50);
86+
insert into student_marks values(2,'Rahul',91);
87+
insert into student_marks values(3,'Amit',74);
88+
insert into student_marks values(4,'Nikhil',65);
89+
insert into student_marks values(5,'Rohit',86);
90+
insert into student_marks values(6,'Deepak',77);
91+
92+
select * from student_marks;
93+
94+
# Write a query to caluclate the grades for a student by following below criteria
95+
# marks >= 90 , grade A+
96+
# marks < 90 and marks >=85, grade A
97+
# marks < 85 and marks >=75, grade B+
98+
# marks < 75 and marks >=60, grade B
99+
# marks < 60 , grade C
100+
101+
select stu_id,
102+
stu_name,
103+
total_marks,
104+
case
105+
when total_marks >=90 then 'A+'
106+
when total_marks >= 85 and total_marks < 90 then 'A'
107+
when total_marks >= 75 and total_marks < 85 then 'B+'
108+
when total_marks >= 60 and total_marks < 75 then 'B'
109+
else 'C'
110+
end as grade
111+
from student_marks;
112+
76113
insert into customer_order_data values(101,200,300,'USA'),(102,201,301,'INDIA'),(103,202,302,'USA'),(104,203,303,'UK');
77114

78115
create table supplier_data

0 commit comments

Comments
 (0)