Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views9 pages

Practical 8 SQL

Uploaded by

aryaamble78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Practical 8 SQL

Uploaded by

aryaamble78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PRACTICAL8

CREATE TABLE Students (


StudentID INT PRIMARY KEY,
Name VARCHAR(100),
Grade CHAR(1)
);
INSERT INTO Students (StudentID, Name, Grade)
VALUES
(1, 'Alice' , 'A'),
(2, 'Bob' , 'B'),
(3, 'Charlie' , 'C'),
(4, 'David' , 'D'),
(5, 'Eva' , 'B'),
(6, 'Frank' , 'A');
1: Simple CASE Statement for Categorizing Grades
Q1. Write a query to classify students based on their grades. Return the student's name
and a performance label (Excellent, Good, Average, Needs Improvement) based on the
grade.
2: Searched CASE Statement for Grade Ranges
Q2. Assume grades have numeric equivalents (A=90, B=80, C=70, D=60). Write a query
that categorizes students into performance bands: High (90 and above), Medium (80-
89), Low (70-79), and Very Low (below 70).

3: Using CASE in a WHERE Clause


Q3. Write a query to select students who either have an A grade or a B grade. However, if
a student has a C grade, include them only if their name starts with 'C'.
4: CASE with Aggregate Functions
Q4. Write a query that calculates the count of students in each performance category
(Excellent, Good, Average, Needs Improvement).

5: Nested CASE Statements


Q5. Write a query that further categorizes students based on their performance:
Excellent if they have an 'A' grade, and Good if they have a 'B' grade. For all other grades,
categorize them based on whether their name starts with a vowel or a consonant.
6: Handling NULL Values with CASE
Q6. Modify the Students table by adding some NULL values in the Grade column. Write
a query to return 'No Grade Assigned' if the grade is NULL.
7: Using CASE in ORDER BY Clause
Q7. Write a query to sort students based on their performance category (Excellent first,
then Good, Average, and Needs Improvement last).
8: Complex CASE Statement with Multiple Conditions
Q8. Write a query to categorize students into three groups: Top Performers (grades 'A'
and 'B' with names starting with 'A' or 'B'), Mid Performers (grade 'C' or 'D'), and Others.
9: Using CASE with Date Functions
Q9. Suppose you add a column EnrollmentDate to the Students table. Write a query
that assigns 'New Student' to those enrolled in 2024, 'Experienced Student' to those
enrolled before 2024, and 'Future Enrollment' to those enrolled in 2025 or later.
10: Combining CASE with String Functions
Q10. Write a query that appends ' (A)' to names with an 'A' grade, ' (B)' to names with a
'B' grade, and so on. If the grade is NULL, append ' (No Grade)'.

You might also like