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

IT RDBMS Practical Ques

The document contains practical SQL questions related to two tables: GYM and Students. It includes various SQL queries for retrieving, updating, and manipulating data such as displaying product names, calculating averages, and filtering records based on conditions. Each question is followed by the corresponding SQL solution and the expected output format.

Uploaded by

gaurigandhi2008
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)
38 views9 pages

IT RDBMS Practical Ques

The document contains practical SQL questions related to two tables: GYM and Students. It includes various SQL queries for retrieving, updating, and manipulating data such as displaying product names, calculating averages, and filtering records based on conditions. Each question is followed by the corresponding SQL solution and the expected output format.

Uploaded by

gaurigandhi2008
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

RDBMS PRACTICAL QUESTIONS

01. Consider the following table named "GYM" with details


about Fitness products being sold in the store.
Table Name : GYM
PrCode stores Codes of Products
PrName stores names of Products (UnitPrice is in Rs.)

PrCode PrName UnitPrice Manufacturer


P101 Cross Trainer 25000 Avon Fitness
P102 Treadmill 32000 AG Fitline
P103 Massage chair 20000 Fit Express
P104 Vibration Trainer 22000 Avon Fitness
P105 Bike 13000 Fit Express

Write SQL statements to do the following:-

A) Display the names of all the products in the store.

Solution:-
SELECT PrName FROM GYM;

PrName
Cross Trainer
Treadmill
Massage chair
Vibration Trainer
Bike

B) Display the names and unit price of all the products in the store
Solution:-
SELECT PrName, UnitPrice FROM GYM;
PrName UnitPrice
Cross Trainer 25000
Treadmill 32000
Massage chair 20000
Vibration Trainer 22000
Bike 13000

C) Display the names of all the products with unit price less than
Rs.20000.00
Solution:-
SELECT PrName FROM GYM WHERE UnitPrice < 20000;
PrName
Bike

D) Display details of all the products with unit price in the range
20000 to 30000
Solution:-
SELECT * FROM GYM WHERE UnitPrice BETWEEN 20000 AND 30000;
PrCode PrName UnitPrice Manufacturer
P101 Cross Trainer 25000 Avon Fitness
P103 Massage chair 20000 Fit Express
P104 Vibration Trainer 22000 Avon Fitness

E) Display names of all products by the manufacturer "Fit Express"


Solution:-
SELECT * FROM GYM WHERE UnitPrice BETWEEN 20000 AND 30000;
PrName
Massage Chair
Bike

F) Display all rows sorted in descending order of unit price.


Solution:-
SELECT * FROM GYM ORDER BY UnitPrice DESC
PrCode PrName UnitPrice Manufacturer
P102 Treadmill 32000 AG Fitline
P101 Cross Trainer 25000 Avon Fitness
P104 Vibration Trainer 22000 Avon Fitness
P103 Massage Chair 20000 Fit Express
P105 Bike 13000 Fit Express

G) Add a new row for product with the details: "P106","Vibro


Exerciser", 23000, manufacturer : "Avon Fitness".
Solution:-
INSERT INTO GYM (PrCode, PrName, UnitPrice, Manufacturer)
VALUES ('P106', 'Vibro Exerciser', 23000, 'Avon Fitness');
PrCode PrName UnitPrice Manufacturer
101 Cross Trainer 25000 Avon Fitness
102 Treadmill 32000 AG Fitline
103 Massage Trainer 20000 Fit Express
104 Vibration Trainer 22000 Avon Fitness
105 Bike 13000 Fit Express
106 Vibro Exercise 23000 Avon Fitness
H) Change the Unit Price data of all the rows by applying a 10%
discount reduction on all the products.
Solution:-
UPDATE GYM SET UnitPrice = UnitPrice * 0.9;
PrCode PrName UnitPrice Manufacturer
101 Cross Trainer 22500 Avon Fitness
102 Treadmill 28800 AG Fitline
103 Massage Trainer 18000 Fit Express
104 Vibration Trainer 19800 Avon Fitness
105 Bike 11700 Fit Express
106 Vibro Exercise 20700 Avon Fitness

I) Display details of all products with manufacturer name starting


with "A".
Solution:-
SELECT * FROM GYM WHERE Manufacturer LIKE 'A%';
PrCode PrName UnitPrice Manufacturer
101 Cross Trainer 25000 Avon Fitness
102 Treadmill 32000 AG Fitline
104 Vibration Trainer 22000 Avon Fitness
106 Vibro Exercise 23000 Avon Fitness
02. Execute the following queries:
Student_ID Name Age Class Score
1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92

1. Write a query to retrieve all the columns from a table named Students.

Solution:-
SELECT* FROM Students;

Student_ID Name Age Class Score


1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92

2. Write a query to find all students with a score greater than 75 from
the Students table.

Solution:-

SELECT * FROM Students WHERE score > 75;

Student_ID Name Age Class Score


1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92

3. Write a query to list all students in the Students table, ordered by


their names in alphabetical order.
Solution:-
SELECT * FROM Students ORDER BY name ASC;
Student_ID Name Age Class Score
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92
2. Jane Smith 17 11B 90
1. John Doe 16 11A 85

4. Write a query to count the total number of students in the Students


table.
Solution:-
SELECT COUNT(*) AS total_students FROM Students;
Total number of Students
5.

5. Write a query to calculate the average score of all students from


the Students table.
Solution:-
SELECT AVG(score) AS average_score FROM Students;
Average_score
86.6

6. Write a query to find the highest score achieved by any student in


the Students table.
Solution:-
SELECT MAX(score) AS highest_score FROM Students;
Highest_score
92

7. Write a query to count the number of students in each class from


the Students table, assuming there's a class column.
Solution:-
SELECT class, COUNT(*) AS student_count FROM Students GROUP BY
class;
Class Student_count
11A 3
11B 1
11C 1

8. Write a query to find classes that have an average score greater than
80.
Solution:-
SELECT class FROM Students GROUP BY class HAVING AVG(score) > 80;
Class
11A
11B
11C

9. Write a query to add a new student to the Students table with the
following details: student_id:10,Name: "John Doe", Age: 16, Class: "11A",
score:90.
Solution:-
INSERT INTO Students (student_id, name, age, class, score)
VALUES (10, 'John Doe', 16, '11A', 90);
Student_ID Name Age Class Score
1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92
10. John Doe 16 11A 90

10. Write a query to update the score of a student named "Jane Smith" to
90 in the Students table.
Solution:-
UPDATE Students SET score = 90 WHERE name = 'Jane Smith';
Student_ID Name Age Class Score
1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92
10. John Doe 16 11A 90

11. Write a query to remove a student record from the Students table
where the student ID is 10.
Solution:-
DELETE FROM Students WHERE student_id = 10;
Student_ID Name Age Class Score
1. John Doe 16 11A 85
2. Jane Smith 17 11B 90
3. Alice Brown 16 11A 78
4. Bob White 17 11C 88
5. Emma Wilson 15 11A 92
12. Write a query to find students whose scores are above the average
score of the class.
Solution:-
SELECT Name, Score
FROM Students
WHERE Score > (SELECT AVG(Score) FROM Students);
Name Score
Jane Smith 90
Bob White 88
Emma Wilson 92

13. Write a query to find all students who are in class "11A" and have a
score greater than 80.

Solution:-
SELECT Name, Score
FROM Students
WHERE Class = '11A' AND Score > 80;
Name Score
John Doe 85
Emma Wilson 92

____________________________________________________________

You might also like