QUESTION 1:
You have a STUDENT table with columns: StudentID, Name, Class, Marks, Section. Write 5 SQL queries to:
Display all students from class XII-A
Display students with marks greater than 75
Display students sorted by marks in descending order
Count total number of students
Display names and marks of students in section B
Table: STUDENT
StudentID Name Class Marks Section
1 Rahul Kumar XII-A 85 A
2 Ananya Sharma XII-A 92 B
3 Priya Singh XII-B 78 A
4 Arjun Patel XII-A 88 B
5 Neha Verma XII-B 95 A
Query 1: Display all students from class XII-A
SELECT * FROM STUDENT WHERE Class = "XII-A";
Output:
StudentID | Name | Class | Marks | Section
1 | Rahul Kumar | XII-A | 85 | A
2 | Ananya Sharma | XII-A | 92 | B
4 | Arjun Patel | XII-A | 88 | B
Query 2: Display students with marks greater than 75
SELECT Name, Marks FROM STUDENT WHERE Marks > 75;
Output:
Name | Marks
Rahul Kumar | 85
Ananya Sharma | 92
Priya Singh | 78
Arjun Patel | 88
Neha Verma | 95
Query 3: Display students sorted by marks in descending order
SELECT Name, Marks FROM STUDENT ORDER BY Marks DESC;
Output:
Name | Marks
Neha Verma | 95
Ananya Sharma | 92
Arjun Patel | 88
Rahul Kumar | 85
Priya Singh | 78
Query 4: Count total number of students
SELECT COUNT(*) AS TotalStudents FROM STUDENT;
Output:
TotalStudents
5
Query 5: Display names and marks of students in section B
SELECT Name, Marks FROM STUDENT WHERE Section = "B";
Output:
Name | Marks
Ananya Sharma | 92
Arjun Patel | 88
QUESTION 2:
You have a SALES table with columns: ProductID, ProductName, Quantity, Price, Date. Write 5 SQL queries to:
Find total quantity sold
Find average price of all products
Find maximum price product
Find minimum quantity sold
Find total revenue (Quantity * Price)
ProductID ProductName Quantity Price Date
1 Notebook 50 20 2025-12-01
2 Pen 100 10 2025-12-02
3 Book 30 150 2025-12-03
4 Pencil 80 5 2025-12-04
5 Eraser 120 2 2025-12-05
Query 1: Find total quantity sold
SELECT SUM(Quantity) AS TotalQuantity FROM SALES;
Output:
TotalQuantity
380
Query 2: Find average price of all products
SELECT AVG(Price) AS AvgPrice FROM SALES;
Output:
AvgPrice
37.4
Query 3: Find maximum price product
SELECT ProductName, MAX(Price) AS MaxPrice FROM SALES;
Output:
ProductName | MaxPrice
Book | 150
Query 4: Find minimum quantity sold
SELECT MIN(Quantity) AS MinQuantity FROM SALES;
Output:
MinQuantity
30
Query 5: Find total revenue
SELECT SUM(Quantity * Price) AS TotalRevenue FROM SALES;
Output:
TotalRevenue
15790
QUESTION 3:
You have two tables - EMPLOYEE (EmpID, Name, DeptID, Salary) and DEPARTMENT (DeptID, DeptName). Write 5 SQL
queries to:
Display employee names with their department names
Display all employees from IT department
Display employee names and salaries from HR department
Count employees in each department
Display highest salary earner name and department
Table 1: EMPLOYEE
EmpID Name DeptID Salary
101 Rahul 1 50000
102 Priya 2 55000
103 Arjun 1 52000
104 Neha 3 48000
Table 2: DEPARTMENT
DeptID DeptName
1 IT
2 HR
3 Finance
Query 1: Display employee names with department names
SELECT [Link], [Link] FROM EMPLOYEE e JOIN DEPARTMENT d ON [Link] = [Link];
Output:
Name | DeptName
Rahul | IT
Priya | HR
Arjun | IT
Neha | Finance
Query 2: Display all employees from IT department
SELECT [Link] FROM EMPLOYEE e JOIN DEPARTMENT d ON [Link] = [Link] WHERE [Link] = "IT";
Output:
Name
Rahul
Arjun
Query 3: Display names and salaries from HR
SELECT [Link], [Link] FROM EMPLOYEE e JOIN DEPARTMENT d ON [Link] = [Link] WHERE [Link] =
"HR";
Output:
Name | Salary
Priya | 55000
Query 4: Count employees in each department
SELECT [Link], COUNT([Link]) AS EmpCount FROM EMPLOYEE e JOIN DEPARTMENT d ON [Link] =
[Link] GROUP BY [Link];
Output:
DeptName | EmpCount
IT | 2
HR | 1
Finance | 1
Query 5: Highest salary earner name and department
SELECT [Link], [Link], [Link] FROM EMPLOYEE e JOIN DEPARTMENT d ON [Link] = [Link] ORDER
BY [Link] DESC LIMIT 1;
Output:
Name | DeptName | Salary
Priya | HR | 55000
QUESTION 4:
You have a LIBRARY table with columns: BookID, Title, Author, Price, Quantity. Write 5 SQL queries to:
Update price of a specific book
Delete books with quantity 0
Increase price of all books by 10%
Update quantity for a book after purchase
Delete books published before 2020
Query 1: Update price of specific book
UPDATE LIBRARY SET Price = 350 WHERE BookID = 1;
Effect:
Book with ID 1 price updated to 350
Query 2: Delete books with quantity 0
DELETE FROM LIBRARY WHERE Quantity = 0;
Effect:
All books with 0 quantity deleted
Query 3: Increase price of all books by 10%
UPDATE LIBRARY SET Price = Price * 1.10;
Effect:
All book prices increased by 10%
Query 4: Update quantity after purchase
UPDATE LIBRARY SET Quantity = Quantity - 5 WHERE BookID = 2;
Effect:
Quantity of Book 2 reduced by 5
Query 5: Delete old books
DELETE FROM LIBRARY WHERE YEAR(PublishDate) < 2020;
Effect:
Books before 2020 deleted
QUESTION 5:
You have a STUDENT_RESULT table with columns: StudentID, StudentName, Subject, Marks. Write 5 SQL queries to:
Find average marks of each student
Find students who scored more than 80 in all subjects
Find top 3 students by average marks
Find subject-wise average marks
Find students who failed any subject (< 40)
StudentID StudentName Subject Marks
1 Rahul Physics 85
1 Rahul Chemistry 88
2 Priya Physics 92
2 Priya Chemistry 90
3 Arjun Physics 78
3 Arjun Chemistry 82
Query 1: Average marks of each student
SELECT StudentName, AVG(Marks) AS AvgMarks FROM STUDENT_RESULT GROUP BY StudentID, StudentName
ORDER BY AvgMarks DESC;
Output:
StudentName | AvgMarks
Priya | 91
Rahul | 86.5
Arjun | 80
Query 2: Students who scored > 80 in all subjects
SELECT DISTINCT StudentName FROM STUDENT_RESULT WHERE Marks > 80 GROUP BY StudentID HAVING COUNT(*)
= (SELECT COUNT(DISTINCT Subject) FROM STUDENT_RESULT WHERE StudentID = STUDENT_RESULT.StudentID);
Output:
StudentName
Rahul
Priya
Query 3: Top 3 students by average marks
SELECT StudentName, AVG(Marks) AS AvgMarks FROM STUDENT_RESULT GROUP BY StudentID ORDER BY AvgMarks
DESC LIMIT 3;
Output:
StudentName | AvgMarks
Priya | 91
Rahul | 86.5
Arjun | 80
Query 4: Subject-wise average marks
SELECT Subject, AVG(Marks) AS AvgMarks FROM STUDENT_RESULT GROUP BY Subject;
Output:
Subject | AvgMarks
Physics | 85
Chemistry | 86.67
Query 5: Students who failed any subject
SELECT DISTINCT StudentName FROM STUDENT_RESULT WHERE Marks < 40;
Output:
StudentName
(No records - all students passed)