Class 12 Informatics Practices - Basic Problems
with Solutions
10 MySQL Problems with Solutions
1. Create a database named 'School'.
Solution:
CREATE DATABASE School;
Expected Output:
Query OK, 1 row affected (0.01 sec)
2. Create a table 'Students' with RollNo, Name, Marks.
Solution:
CREATE TABLE Students (RollNo INT PRIMARY KEY, Name VARCHAR(50), Marks INT);
Expected Output:
Query OK, 0 rows affected (0.02 sec)
3. Insert 5 records into 'Students' table.
Solution:
INSERT INTO Students VALUES (1,'Amit',90),(2,'Riya',85),(3,'Karan',70),(4,'Suma
Expected Output:
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
4. Display all records from 'Students'.
Solution:
SELECT * FROM Students;
Expected Output:
+--------+-------+-------+
| RollNo | Name | Marks |
+--------+-------+-------+
| 1 | Amit | 90 |
| 2 | Riya | 85 |
| 3 | Karan | 70 |
| 4 | Suman | 88 |
| 5 | Pooja | 95 |
+--------+-------+-------+
5 rows in set (0.00 sec)
5. Display names of students who scored more than 80.
Solution:
SELECT Name FROM Students WHERE Marks>80;
Expected Output:
+-------+
| Name |
+-------+
| Amit |
| Riya |
| Suman |
| Pooja |
+-------+
4 rows in set (0.00 sec)
6. Update marks of 'Karan' to 75.
Solution:
UPDATE Students SET Marks=75 WHERE Name='Karan';
Expected Output:
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
7. Delete record of student with RollNo=2.
Solution:
DELETE FROM Students WHERE RollNo=2;
Expected Output:
Query OK, 1 row affected (0.00 sec)
8. Display average marks of students.
Solution:
SELECT AVG(Marks) FROM Students;
Expected Output:
+------------+
| AVG(Marks) |
+------------+
| 87.0000 |
+------------+
1 row in set (0.00 sec)
9. Display maximum and minimum marks.
Solution:
SELECT MAX(Marks), MIN(Marks) FROM Students;
Expected Output:
+------------+------------+
| MAX(Marks) | MIN(Marks) |
+------------+------------+
| 95 | 70 |
+------------+------------+
1 row in set (0.00 sec)
10. Display students in descending order of marks.
Solution:
SELECT * FROM Students ORDER BY Marks DESC;
Expected Output:
+--------+-------+-------+
| RollNo | Name | Marks |
+--------+-------+-------+
| 5 | Pooja | 95 |
| 1 | Amit | 90 |
| 4 | Suman | 88 |
| 3 | Karan | 75 |
+--------+-------+-------+
4 rows in set (0.00 sec)