0% found this document useful (0 votes)
753 views39 pages

(Q Query) : Q.1. Create A Table Name As Student and Enter Any Six Records

The document describes queries performed on MySQL databases to create and populate tables with student and club records, and then queries to retrieve data from the tables. The key points are: 1) Two tables were created - Student with 6 records about students, and Club with 8 records about coaches. 2) Multiple SELECT queries were performed to retrieve and display data from the tables based on various criteria like grade, name, sport etc. 3) The tables were populated with sample data like student details, coach details, and then different queries displayed the records based on conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
753 views39 pages

(Q Query) : Q.1. Create A Table Name As Student and Enter Any Six Records

The document describes queries performed on MySQL databases to create and populate tables with student and club records, and then queries to retrieve data from the tables. The key points are: 1) Two tables were created - Student with 6 records about students, and Club with 8 records about coaches. 2) Multiple SELECT queries were performed to retrieve and display data from the tables based on various criteria like grade, name, sport etc. 3) The tables were populated with sample data like student details, coach details, and then different queries displayed the records based on conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 39

(Q=Query)

Q.1. Create a table name as Student and enter any six records.

Mysql> create table Student(StudentNo int(2), Class int(2), Name char(10), Game
char(15),
Grade1 char(1), Supw char(20), Grade2 char(2));
Query OK, 0 rows affected(2.60sec)

mysql> insert into student values(10, 7, 'Sameer', 'Cricket', 'B', 'Photography', 'B');
Query OK, 1 row affected (0.41 sec)

mysql> insert into student values(11, 8, 'Sujit', 'Tennis', 'A', 'Photography', 'C');
Query OK, 1 row affected (0.14 sec)

mysql> insert into student values(12, 7, 'Kamal', 'Swimming', 'B', 'Photography',


'B');
Query OK, 1 row affected (0.08 sec)

mysql> insert into student values(13, 7, 'Veena', 'Tennis', 'C', 'Cooking', 'A');
Query OK, 1 row affected (0.29 sec)

mysql> insert into student values(14, 9, 'Archana', 'Basketball', 'A', 'Literature',


'A');
Query OK, 1 row affected (0.12 sec)

mysql> insert into student values(15, 10, 'Arpit', 'Cricket', 'A', 'Gardening', 'C');
Query OK, 1 row affected (0.27 sec)

mysql> select *from student;


+-----------+-------+---------+------------+--------+-------------+--------+
| StudentNo | Class | Name | Game | Grade1 | SUPW
| Grade2 |
+-----------+-------+---------+------------+--------+-------------+--------+
| 10 | 7 | Sameer | Cricket | B |
Photography | B |
| 11 | 8| Sujit | Tennis | A |
Photography | C |
| 12 | 7| Kamal | Swimming | B |
Photography | B |
| 13 | 7| Veena | Tennis | C |
Cooking | A |
| 14 | 9 | Archana | Basketball | A |
Literature | A |
| 15 | 10 | Arpit | Cricket | A |
Gardening | C |
+-----------+-------+---------+------------+--------+-------------+--------+
6 rows in set (0.11 sec)

Q.2. Display the names of the students who are getting a grade 'C' in either Game
or SUPW.

mysql> select *from student where Grade1=Grade2='C';

+-----------+-------+-------+---------+--------+-------------+--------+
| StudentNo | Class | Name | Game | Grade1 | SUPW |
Grade2 |
+-----------+-------+-------+---------+--------+-------------+--------+
| 11 | 8| Sujit | Tennis | A |
Photography | C |
| 13 | 7 | Veena | Tennis | C | Cooking
| A |
| 15 | 10 | Arpit | Cricket | A |
Gardening | C |
+-----------+-------+-------+---------+--------+-------------+--------+
3 rows in set, 1 warning (0.15 sec)

Q.3. Display the different games offered in the school.

mysql> select distinct(game) from student;


+------------+
| game |
+------------+
| Cricket |
| Tennis |
| Swimming |
| Basketball |
+------------+
4 rows in set (1.57 sec)
Q.4. Display the SUPW taken by students whose names starts with 'A'.

mysql> select Name, Supw from Student where Name like '%A';
+---------+------------+
| Name | Supw |
+---------+------------+
| Veena | Cooking |
| Archana | Literature |
+---------+------------+
2 rows in set (0.10 sec)

Q.5 Create a table named as CLUB with 8 records.

mysql> Create table Club(Coach_ID int(2), CoachName char(10), Age int(2),


Sports char(10), DateOfApp date, Pay int(5), sex char(1));
Query OK, 0 rows affected (3.53 sec)

mysql> insert into Club values(1,'Kukreja',35,'Karate','1996-03-27',1000,'M');


Query OK, 1 row affected (0.41 sec)

mysql> insert into Club values(2,'Ravina',34,'Karate','1998-01-20',1200,'F');


Query OK, 1 row affected (0.12 sec)
mysql> insert into Club values(3,'Karan',34,'Squash','1998-02-19',2000,'M');
Query OK, 1 row affected (0.08 sec)

mysql> insert into Club values(4,'Tarun',33,'Basketball','2000-01-01',1500,'M');


Query OK, 1 row affected (0.24 sec)

mysql> insert into Club values(5,'Zubin',36,'Swimmimg','2001-01-12',750,'M');


Query OK, 1 row affected (0.16 sec)

mysql> insert into Club values(6,'Ketaki',36,'Swimmimg','2002-02-24',800,'F');


Query OK, 1 row affected (0.14 sec)

mysql> insert into Club values(7,'Ankita',39,'Squash','2003-02-20',2200,'F');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Club values(8,'Zareen',37,'Karate','2004-02-22',1100,'F');


Query OK, 1 row affected (0.12 sec)
mysql> select *from Club;
+----------+-----------+------+------------+------------+------+------+
| Coach_ID | CoachName| Age | Sports | DateOfApp | Pay |
sex |
+----------+-----------+------+------------+------------+------+------+
| 1| Kukreja | 35 | Karate | 1996-03-27 | 1000
| M |
| 2| Ravina | 34 | Karate | 1998-01-20 | 1200 |
F |
| 3| Karan | 34 | Squash | 1998-02-19 | 2000 |
M |
| 4| Tarun | 33 | Basketball | 2000-01-01 | 1500 |
M |
| 5| Zubin | 36 | Swimming | 2001-01-12 | 750 |
M |
| 6| Ketaki | 36 | Swimming | 2002-02-24 | 800 |
F |
| 7| Ankita | 39 | Squash | 2003-02-20 | 2200 |
F |
| 8| Zareen | 37 | Karate 2004-02-22 | 1100 |
F |
+----------+-----------+------+------------+------------+------+------+
8 rows in set (0.03 sec)

Q6. To show all information about the swimming coaches in the club.

mysql> select *from Club where Sports='Swimming';


+----------+-----------+------+----------+------------+------+------+
| Coach_ID |CoachName | Age | Sports | DateOfApp | Pay |
sex |
+----------+-----------+------+----------+------------+------+------+
| 5| Zubin | 36 | Swimming | 2001-01-12 | 750 |
M |
| 6| Ketaki | 36 | Swimming | 2002-02-24 | 800 |
F |
+----------+-----------+------+----------+------------+------+------+
2 rows in set (0.00 sec)

Q.7. To list names of all coaches with their date of appointment in descending
order.

mysql> select CoachName, DateOfApp from Club order by DateOfApp desc;


+-----------+------------+
| CoachName | DateOfApp |
+-----------+------------+
| Zareen | 2004-02-22 |
| Ankita | 2003-02-20 |
| Ketaki | 2002-02-24 |
| Zubin | 2001-01-12 |
| Tarun | 2000-01-01 |
| Karan | 1998-02-19 |
| Ravina | 1998-01-20 |
| Kukreja | 1996-03-27 |
+-----------+------------+
8 rows in set (0.07 sec)

Q.8. To display a report showing CoachName, Pay , Age and bonus(15% on Pay)
for all the coaches.

mysql> select CoachName, Pay, Age, 15*Pay/100 "Bonus" from Club;


+-----------+------+------+----------+
| CoachName | Pay | Age | Bonus |
+-----------+------+------+----------+
| Kukreja | 1000 | 35 | 150.0000 |
| Ravina | 1200 | 34 | 180.0000 |
| Karan | 2000 | 34 | 300.0000 |
| Tarun | 1500 | 33 | 225.0000 |
| Zubin | 750 | 36 | 112.5000 |
| Ketaki | 800 | 36 | 120.0000 |
| Ankita | 2200 | 39 | 330.0000 |
| Zareen | 1100 | 37 | 165.0000 |
+-----------+------+------+----------+
8 rows in set (0.11 sec)

Q.9. Create table named as Student with 8 records.

mysql> Create table Student(No int(1), Name char(10), Stipend float(5), Stream
char(15), AvgMark float(3), Grade char(1), Class varchar(4));
Query OK, 0 rows affected (0.65 sec)

mysql> insert into Student values(1,'Karan',400.00,'Medical',78.5,'B','12B');


Query OK, 1 row affected (0.19 sec)

mysql> insert into Student values(2,'Divakar',450.00,'Commerce',89.2,'A','11C');


Query OK, 1 row affected (0.13 sec)

mysql> insert into Student values(3,'Divya',300.00,'Commerce',68.6,'C','12C');


Query OK, 1 row affected (0.07 sec)

mysql> insert into Student values(4,'Arun',350.00,'Humanities',73.1,'B','12C');


Query OK, 1 row affected (0.17 sec)

mysql> insert into Student values(5,'Sabina',500.00,'Non-Medical',90.6,'A','11A');


Query OK, 1 row affected (0.08 sec)

mysql> insert into Student values(6,'John',400.00,'Medical',75.4,'B','12B');


Query OK, 1 row affected (0.18 sec)

mysql> insert into Student values(7,'Robert',250.00,'Humanities',64.4,'C','11A');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Student values(8,'Rubina',450.00,'Non-


Medical',88.5,'A','12A');
Query OK, 1 row affected (0.10 sec)

mysql> select *from student;

+------+---------+---------+-------------+---------+-------+-------+
| No | Name | Stipend | Stream | AvgMark | Grade |
Class |
+------+---------+---------+-------------+---------+-------+-------+
| 1| Karan | 400 | Medical | 78.5 | B |
12B |
| 2 | Divakar | 450 | Commerce | 89.2 | A |
11C |
| 3| Divya | 300 | Commerce | 68.6 | C |
12C |
| 4 | Arun | 350 | Humanities | 73.1 | B |
12C |
| 5 | Sabina | 500 | Non-Medical | 90.6 | A |
11A |
| 6 | John | 400 | Medical | 75.4 | B |
12B |
| 7 | Robert | 250 | Humanities | 64.4 | C |
11A |
| 8 | Rubina | 450 | Non-Medical | 88.5 | A |
12A |
+------+---------+---------+-------------+---------+-------+-------+
8 rows in set (0.05 sec)

Q.10. Select all non-medical stream students from student.

mysql> select *from student where Stream='Non-Medical';


+------+--------+---------+-------------+---------+-------+-------+
| No | Name | Stipend | Stream | AvgMark | Grade | Class
|
+------+--------+---------+-------------+---------+-------+-------+
| 5 | Sabina | 500 | Non-Medical | 90.6 | A |
11A |
| 8 | Rubina | 450 | Non-Medical | 88.5 | A |
12A |
+------+--------+---------+-------------+---------+-------+-------+
2 rows in set (0.00 sec)

Q.11. List all students sorted by AvgMark in descending order.

mysql> select *from student order by AvgMark desc;

+------+---------+---------+-------------+---------+-------+-------+
| No | Name | Stipend | Stream | AvgMark | Grade |
Class |
+------+---------+---------+-------------+---------+-------+-------+
| 5 | Sabina | 500 | Non-Medical | 90.6 | A |
11A |
| 2 | Divakar | 450 | Commerce | 89.2 | A |
11C |
| 8 | Rubina | 450 | Non-Medical | 88.5 | A |
12A |
| 1| Karan | 400 | Medical | 78.5 | B |
12B |
| 6 | John | 400 | Medical | 75.4 | B |
12B |
| 4 | Arun | 350 | Humanities | 73.1 | B |
12C |
| 3| Divya | 300 | Commerce | 68.6 | C |
12C |
| 7 | Robert | 250 | Humanities | 64.4 | C |
11A |
+------+---------+---------+-------------+---------+-------+-------+
8 rows in set (0.00 sec)

Q.12. Display a report listing name, stipend and amount of stipend received in a
year assuming that stipend is paid every month.

mysql> select Name, Stipend, Stipend*12 "Stipend Year" from student;

+---------+---------+--------------+
| Name | Stipend | Stipend Year |
+---------+---------+--------------+
| Karan | 400 | 4800 |
| Divakar | 450 | 5400 |
| Divya | 300 | 3600 |
| Arun | 350 | 4200 |
| Sabina | 500 | 6000 |
| John | 400 | 4800 |
| Robert | 250 | 3000 |
| Rubina | 450 | 5400 |
+---------+---------+--------------+
8 rows in set (0.01 sec)

Q.13. Create table named as library with 8 records.

mysql> create table Library(No int(1), Title char(30), Author char(15), Type
char(5), Pub char(10), Qty int(1), Price int(4));
Query OK, 0 rows affected (0.78 sec)

mysql> insert into Library values(1,'Data


Structure','Lipschutz','DS','McGraw',4,217);
Query OK, 1 row affected (0.15 sec)

mysql> insert into Library values(2,'Computer


Studies','French','FND','Galgotia',2,75);
Query OK, 1 row affected (0.11 sec)

mysql> insert into Library values(3,'Adavnced


Pascal','Schildt','PROG','McGraw',4,350);
Query OK, 1 row affected (0.08 sec)

mysql> insert into Library


values(4,'Dbasedummies','Palmer','DBMS','PustakM',5,130);
Query OK, 1 row affected (0.23 sec)

mysql> insert into Library values(5,'Mastering C+


+','Gurewich','PROG','BPB',2,295);
Query OK, 1 row affected (0.11 sec)

mysql> insert into Library values(6,'GuideNetwork','Freed','NET','Zpress',3,200);


Query OK, 1 row affected (0.13 sec)

mysql> insert into Library


values(7,'MasteringFoxpro','Seigal','DBMS','BPB',2,135);
Query OK, 1 row affected (0.07 sec)

mysql> insert into Library values(8,'DOSGuide','Norton','OS','PHI',3,175);


Query OK, 1 row affected (0.13 sec)

mysql> select *from Library;

+------+------------------+-----------+------+----------+------+-------+
| No | Title | Author | Type | Pub |
Qty | Price |
+------+------------------+-----------+------+----------+------+-------+
| 1| Data Structure | Lipschutz | DS | McGraw | 4|
217 |
| 2 | Computer Studies | French | FND | Galgotia | 2|
75 |
| 3 | Adavnced Pascal | Schildt | PROG | McGraw | 4|
350 |
| 4 | Dbasedummies | Palmer | DBMS | PustakM | 5
| 130 |
| 5| Mastering C++ | Gurewich | PROG | BPB | 2
| 295 |
| 6| GuideNetwork | Freed | NET | Zpress | 3
| 200 |
| 7 | MasteringFoxpro | Seigal | DBMS | BPB | 2
| 135 |
| 8| DOSGuide | Norton | OS | PHI | 3
| 175 |
+------+------------------+-----------+------+----------+------+-------+
8 rows in set (0.00 sec)
Q.14. Select all the PROG type published by BPB from Library.

mysql> select *from Library where Type='PROG' and Pub='BPB';


+------+---------------+----------+------+------+------+-------+
| No | Title | Author | Type | Pub | Qty | Price
|
+------+---------------+----------+------+------+------+-------+
| 5 | Mastering C++ | Gurewich | PROG | BPB | 2| 295
|
+------+---------------+----------+------+------+------+-------+
1 row in set (2.63 sec)

Q.15. Display a list of all the books with Price more than 130 and sorted by Qty.

mysql> select *from Library where Price>130 order by Qty asc;


+------+-----------------+-----------+------+--------+------+-------+
| No | Title | Author | Type | Pub | Qty |
Price |
+------+-----------------+-----------+------+--------+------+-------+
| 5| Mastering C++ | Gurewich | PROG | BPB | 2|
295 |
| 7 | MasteringFoxpro | Seigal | DBMS | BPB | 2|
135 |
| 6| GuideNetwork | Freed | NET | Zpress | 3|
200 |
| 8| DOSGuide | Norton | OS | PHI |
3| 175 |
| 1| Data Structure | Lipschutz | DS | McGraw | 4|
217 |
| 3 | Adavnced Pascal | Schildt | PROG | McGraw | 4|
350 |
+------+-----------------+-----------+------+--------+------+-------+
6 rows in set (0.10 sec)

Q.16. Display all the books sorted by price in ascending order.


mysql> select *from Library order by Price asc;
+------+------------------+-----------+------+----------+------+-------+
| No | Title | Author | Type | Pub |
Qty | Price |
+------+------------------+-----------+------+----------+------+-------+
| 2 | Computer Studies | French | FND | Galgotia | 2|
75 |
| 4 | Dbasedummies | Palmer | DBMS | PustakM | 5
| 130 |
| 7 | MasteringFoxpro | Seigal | DBMS | BPB | 2
| 135 |
| 8| DOSGuide | Norton | OS | PHI | 3
| 175 |
| 6| GuideNetwork | Freed | NET | Zpress | 3
| 200 |
| 1| Data Structure | Lipschutz | DS | McGraw | 4|
217 |
| 5| Mastering C++ | Gurewich | PROG | BPB | 2
| 295 |
| 3 | Adavnced Pascal | Schildt | PROG | McGraw | 4|
350 |
+------+------------------+-----------+------+----------+------+-------+
8 rows in set (0.00 sec)

Q.17. Create table named as Graduate with 8 records.

mysql> Create table Graduate(Sno int(1), Name char(10), Stipend int(3), Subject
char(15), Avg int(2), Rnk int(1));
Query OK, 0 rows affected (1.16 sec)

mysql> insert into Graduate values(1,'Karan',400,'Physics',68,1);


Query OK, 1 row affected (0.21 sec)

mysql> insert into Graduate values(2,'Divakar',450,'Computer Sc',68,1);


Query OK, 1 row affected (0.14 sec)

mysql> insert into Graduate values(3,'Divya',300,'Chemistry',62,2);


Query OK, 1 row affected (0.10 sec)

mysql> insert into Graduate values(4,'Arun',350,'Physics',63,1);


Query OK, 1 row affected (0.14 sec)
mysql> insert into Graduate values(5,'Sabina',500,'Mathematics',70,1);
Query OK, 1 row affected (0.09 sec)

mysql> insert into Graduate values(6,'John',400,'Chemistry',55,2);


Query OK, 1 row affected (0.13 sec)

mysql> insert into Graduate values(7,'Robert',250,'Physics',64,1);


Query OK, 1 row affected (0.10 sec)

mysql> insert into Graduate values(8,'Rubina',450,'Mathematics',68,1);


Query OK, 1 row affected (0.14 sec)

mysql> select *from Graduate;

+------+---------+---------+-------------+------+------+
| Sno | Name | Stipend | Subject | Avg | Rnk |
+------+---------+---------+-------------+------+------+
| 1| Karan | 400 | Physics | 68 | 1|
| 2 | Divakar | 450 | Computer Sc | 68 | 1|
| 3| Divya | 300 | Chemistry | 62 | 2|
| 4| Arun | 350 | Physics | 63 | 1|
| 5 | Sabina | 500 | Mathematics | 70 | 1|
| 6| John | 400 | Chemistry | 55 | 2|
| 7| Robert | 250 | Physics | 64 | 1|
| 8 | Rubina | 450 | Mathematics | 68 | 1|
+------+---------+---------+-------------+------+------+
8 rows in set (0.00 sec)

Q.18. List the names of those students who have obtained Rank 1 sorted by name.

mysql> select *from Graduate where Rnk=1 order by Name;


+------+---------+---------+-------------+------+------+
| Sno | Name | Stipend | Subject | Avg | Rnk |
+------+---------+---------+-------------+------+------+
| 4| Arun | 350 | Physics | 63 | 1|
| 2 | Divakar | 450 | Computer Sc | 68 | 1|
| 1| Karan | 400 | Physics | 68 | 1|
| 7| Robert | 250 | Physics | 64 | 1|
| 8 | Rubina | 450 | Mathematics | 68 | 1|
| 5 | Sabina | 500 | Mathematics | 70 | 1|
+------+---------+---------+-------------+------+------+
6 rows in set (0.02 sec)

Q.19. Display a report listing Name, Stipend, Subject and amount of stipend
received in a year assuming that the stipend is paid every month.

mysql> select Name, Stipend, Subject, Stipend*12 "Stipend Year" from Graduate;

+---------+---------+-------------+--------------+
| Name | Stipend | Subject | Stipend Year |
+---------+---------+-------------+--------------+
| Karan | 400 | Physics | 4800 |
| Divakar | 450 | Computer Sc | 5400 |
| Divya | 300 | Chemistry | 3600 |
| Arun | 350 | Physics | 4200 |
| Sabina | 500 | Mathematics | 6000 |
| John | 400 | Chemistry | 4800 |
| Robert | 250 | Physics | 3000 |
| Rubina | 450 | Mathematics | 5400 |
+---------+---------+-------------+--------------+
8 rows in set (0.05 sec)

Q.20. Create table named as Teacher with 8 records.

mysql> create table Teacher(No int(1), Name char(10), Age int(2), Dept char(10),
DOJ date, Salary int(5), Sex char(1));
Query OK, 0 rows affected (0.48 sec)
mysql> insert into Teacher values(1,'Jugal',34,'Computer','2005-01-
10',12000,'M');
Query OK, 1 row affected (0.12 sec)

mysql> insert into Teacher values(2,'Sharmila',31,'History','2012-03-


24',20000,'F');
Query OK, 1 row affected (0.19 sec)

mysql> insert into Teacher values(3,'Sandeep',32,'Maths','2018-12-12',30000,'M');


Query OK, 1 row affected (0.08 sec)
mysql> insert into Teacher values(4,'Sangeeta',35,'History','2008-07-
01',40000,'F');
Query OK, 1 row affected (0.14 sec)

mysql> insert into Teacher values(5,'Rakesh',42,'Maths','2005-09-05',25000,'M');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Teacher values(6,'Shyam',50,'History','2012-06-27',30000,'M');


Query OK, 1 row affected (0.42 sec)

mysql> insert into Teacher values(7,'Shiva',44,'Computer','2005-02-


25',21000,'M');
Query OK, 1 row affected (0.07 sec)

mysql> insert into Teacher values(8,'Shalakha',33,'Maths','2005-07-31',20000,'F');


Query OK, 1 row affected (0.46 sec)

mysql> select *from Teacher;

+------+----------+------+----------+------------+--------+------+
| No | Name | Age | Dept | DOJ | Salary |
Sex |
+------+----------+------+----------+------------+--------+------+
| 1| Jugal | 34 | Computer | 2005-01-10 | 12000 | M
|
| 2 | Sharmila | 31 | History | 2012-03-24 | 20000 | F |
| 3 | Sandeep | 32 | Maths | 2018-12-12 | 30000 | M
|
| 4 | Sangeeta | 35 | History | 2008-07-01 | 40000 | F |
| 5 | Rakesh | 42 | Maths | 2005-09-05 | 25000 | M |
| 6 | Shyam | 50 | History | 2012-06-27 | 30000 | M |
| 7 | ShivOm | 44 | Computer | 2005-02-25 | 21000 | M |
| 8 | Shalakha | 33 | Maths | 2005-07-31 | 20000 | F |
+------+----------+------+----------+------------+--------+------+
8 rows in set (0.00 sec)

Q.21. To show all information about the teacher of Maths Department.

mysql> select *from Teacher where Dept='Maths';;


+------+----------+------+-------+------------+--------+------+
| No | Name | Age | Dept | DOJ | Salary | Sex |
+------+----------+------+-------+------------+--------+------+
| 3 | Sandeep | 32 | Maths | 2018-12-12 | 30000 | M |
| 5 | Rakesh | 42 | Maths | 2005-09-05 | 25000 | M |
| 8 | Shalakha | 33 | Maths | 2005-07-31 | 20000 | F |
+------+----------+------+-------+------------+--------+------+
3 rows in set (0.00 sec)

Q.22. To list the names of female teachers who are in History Department.

mysql> select *from Teacher where Dept='History' and Sex='F';

+------+----------+------+---------+------------+--------+------+
| No | Name | Age | Dept | DOJ | Salary |
Sex |
+------+----------+------+---------+------------+--------+------+
| 2 | Sharmila | 31 | History | 2012-03-24 | 20000 | F |
| 4 | Sangeeta | 35 | History | 2008-07-01 | 40000 | F |
+------+----------+------+---------+------------+--------+------+
2 rows in set (0.00 sec)

Q.23. To list the names of teachers with their date of joining in ascending order.

mysql> select *from Teacher order by DOJ;

+------+----------+------+----------+------------+--------+------+
| No | Name | Age | Dept | DOJ | Salary |
Sex |
+------+----------+------+----------+------------+--------+------+
| 1| Jugal | 34 | Computer | 2005-01-10 | 12000 | M
|
| 7 | ShivOm | 44 | Computer | 2005-02-25 | 21000 | M |
| 8 | Shalakha | 33 | Maths | 2005-07-31 | 20000 | F |
| 5 | Rakesh | 42 | Maths | 2005-09-05 | 25000 | M |
| 4 | Sangeeta | 35 | History | 2008-07-01 | 40000 | F |
| 2 | Sharmila | 31 | History | 2012-03-24 | 20000 | F |
| 6 | Shyam | 50 | History | 2012-06-27 | 30000 | M |
| 3 | Sandeep | 32 | Maths | 2018-12-12 | 30000 | M
|
+------+----------+------+----------+------------+--------+------+
8 rows in set (0.00 sec)
Q.24. Write a command to convert a string into lower case and upper case.

mysql> select Lcase('OBAMA') as 'Lower Case',


-> 'Obama' as 'Normal',
-> Ucase('obama') as 'UpperCase';

+------------+--------+-----------+
| Lower Case | Normal | UpperCase |
+------------+--------+-----------+
| obama | Obama | OBAMA |
+------------+--------+-----------+
1 row in set (0.11 sec)

Q.25. Write a command to extract a sub string from given string.

mysql> select substr('ABCDEFGHIJKL',4,7) "Sub String";


+------------+
| Sub String |
+------------+
| DEFGHIJ |
+------------+
1 row in set (0.00 sec)
Q.26. Write a command to remove leading spaces.

mysql> select Ltrim(' IP PRACTICAL FILE') "Ltrim";


+-------------------+
| Ltrim |
+-------------------+
| IP PRACTICAL FILE |
+-------------------+
1 row in set (0.03 sec)

Q.27. Write a command to remove trailing spaces.

mysql> select Rtrim('IP PRACTICAL FILE ') "Rtrim";


+-------------------+
| Rtrim |
+-------------------+
| IP PRACTICAL FILE |
+-------------------+
1 row in set (0.00 sec)
Q.28. Write a command to remove both leading and trailing spaces.

mysql> select Trim(' IP PRACTICAL FILE ') "Trim";


+-------------------+
| Trim |
+-------------------+
| IP PRACTICAL FILE |
+-------------------+
1 row in set (0.03 sec)

Q.29. Write a command to return the length of the string.

mysql> select Length('MY SQL') "Length";


+--------+
| Length |
+--------+
| 6|
+--------+
1 row in set (0.02 sec)

Q.30. Write a command to return left most and right most characters of the given
expression.

mysql> select Left('USS/23/67/09',3) "LeftMost",


-> Right('USS/23/67/09',2) "RightMost";
+----------+-----------+
| LeftMost | RightMost |
+----------+-----------+
| USS | 09 |
+----------+-----------+
1 row in set (0.00 sec)

Q.31. Write a command to return all mathematical answers for two numbers 9
and 6.

mysql> select 9+6 "Addition",


-> 9-6 "Substraction",
-> 9*6 "Multplication",
-> 9/6 "Division",
-> 9%6 "Modulus";
+----------+--------------+---------------+----------+---------+
| Addition | Substraction | Multplication | Division | Modulus |
+----------+--------------+---------------+----------+---------+
| 15 | 3| 54 | 1.5000 |
3|
+----------+--------------+---------------+----------+---------+
1 row in set (0.05 sec)

Q.32. Write a command to return Power, Round and Square Root.


mysql> select Power(8,3) "Power",
-> Round(15.193,1) "Round",
-> SQRT(81) "Square Root";

+-------+-------+-------------+
| Power | Round | Square Root |
+-------+-------+-------------+
| 512 | 15.2 | 9|
+-------+-------+-------------+
1 row in set (0.07 sec)

Q.33. Write a command to get the Current Date.

mysql> select CurDate();


+------------+
| CurDate() |
+------------+
| 2019-10-13 |
+------------+
1 row in set (0.04 sec)

Q.34. Write a command to return the day, month and year from the gien date.

mysql> select Day('2018-10-36') "Day",


-> Month('2018-10-36') "Month",
-> Year('2018-10-36') "Year";
+------+-------+------+
| Day | Month | Year |
+------+-------+------+
| 26 | 10 | 2018 |
+------+-------+------+
1 row in set, 3 warnings (0.04 sec)
Q.35. Write a command to return DayName, Day of week and Day of Year.

mysql> select DayName('2018-10-26') "Day Name",


-> DayOfWeek('2018-10-26') "Day of Week",
-> DayOfYear('2018-10-26') "Day of Year";
+----------+-------------+-------------+
| Day Name | Day of Week | Day of Year |
+----------+-------------+-------------+
| Friday | 6 | 299 |
+----------+-------------+-------------+
1 row in set (0.05 sec)

Q.36. Write a command to create a table named as Garment.

mysql> create table Garment(GCODE int(3), GNAME char(15), SIZE char(3),


COLOUR char(10), PRICE decimal(7,2));
Query OK, 0 rows affected (2.24 sec)

mysql> insert into Garment values(111,'TShirt','XL','Red',1400.00);


Query OK, 1 row affected (0.39 sec)

mysql> insert into Garment values(112,'Jeans','L','Blue',1600.00);


Query OK, 1 row affected (0.16 sec)

mysql> insert into Garment values(113,'Skirt','M','Black',1100.00);


Query OK, 1 row affected (0.27 sec)

mysql> insert into Garment values(114,'Ladies Jacket','XL','Blue',4000.00);


Query OK, 1 row affected (0.14 sec)

mysql> insert into Garment values(115,'Trousers','L','Brown',1500.00);


Query OK, 1 row affected (0.10 sec)

mysql> insert into Garment values(116,'Ladies Top','L','Pink',1200.00);


Query OK, 1 row affected (0.10 sec)

mysql> select *from Garment;


+-------+---------------+------+--------+---------+
| GCODE | GNAME | SIZE | COLOUR | PRICE |
+-------+---------------+------+--------+---------+
| 111 | TShirt | XL | Red | 1400.00 |
| 112 | Jeans | L | Blue | 1600.00 |
| 113 | Skirt | M | Black | 1100.00 |
| 114 | Ladies Jacket | XL | Blue | 4000.00 |
| 115 | Trousers | L | Brown | 1500.00 |
| 116 | Ladies Top | L | Pink | 1200.00 |
+-------+---------------+------+--------+---------+
6 rows in set (0.12 sec)

Q.37.Display the names of those garments that are available in 'XL' size.

mysql> select *from Garment where size='XL';


+-------+---------------+------+--------+---------+
| GCODE | GNAME | SIZE | COLOUR | PRICE |
+-------+---------------+------+--------+---------+
| 111 | TShirt | XL | Red | 1400.00 |
| 114 | Ladies Jacket | XL | Blue | 4000.00 |
+-------+---------------+------+--------+---------+
2 rows in set (0.12 sec)

Q.38.Display codes and names of those garments that have their names starting
with Ladies.

mysql> select Gcode, Gname from Garment where Gname like 'Ladies%';

+-------+---------------+
| GCODE | GNAME |
+-------+---------------+
| 114 | Ladies Jacket |
| 116 | Ladies Top |
+-------+---------------+

2 rows in set (0.07 sec)

Q.39. Display names, codes and prices of those garments that have price in the
range 1000.00 to 1500.00.

mysql> select Gcode, Gname, Price from Garment where Price>=1000 and
Price<=1500;

+-------+------------+---------+
| GCODE | GNAME | PRICE |
+-------+------------+---------+
| 111 | TShirt | 1400.00 |
| 113 | Skirt | 1100.00 |
| 115 | Trousers | 1500.00 |
| 116 | Ladies Top | 1200.00 |
+-------+------------+---------+

4 rows in set (0.00 sec)

Q.40.Change the colour of garment with code as 116 to 'Orange'.

mysql> update Garment set Colour='Orange' where Gcode=116;


Query OK, 1 row affected (0.14 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Q.41. Write a command to create a table named as Soft Drink.

mysql> create table SoftDrink(DCODE int(3), DNAME char(20), PRICE


decimal(5,2), CALORIES int(3));
Query OK, 0 rows affected (0.82 sec)

mysql> insert into SoftDrink values(101,'Lime and Lemon',20.00,120);


Query OK, 1 row affected (0.11 sec)

mysql> insert into SoftDrink values(102,'Apple Drink',18.00,120);


Query OK, 1 row affected (0.14 sec)

mysql> insert into SoftDrink values(103,'Nature Nectar',15.00,115);


Query OK, 1 row affected (0.07 sec)

mysql> insert into SoftDrink values(104,'Green Mango',15.00,140);


Query OK, 1 row affected (0.13 sec)

mysql> insert into SoftDrink values(105,'Aam Panna',20.00,135);


Query OK, 1 row affected (0.39 sec)

mysql> insert into SoftDrink values(106,'Mango Juice Bahaar',12.00,150);


Query OK, 1 row affected (0.11 sec)

mysql> select *from SoftDrink;


+-------+--------------------+-------+----------+
| DCODE | DNAME | PRICE | CALORIES |
+-------+--------------------+-------+----------+
| 101 | Lime and Lemon | 20.00 | 120 |
| 102 | Apple Drink | 18.00 | 120 |
| 103 | Nature Nectar | 15.00 | 115 |
| 104 | Green Mango | 15.00 | 140 |
| 105 | Aam Panna | 20.00 | 135 |
| 106 | Mango Juice Bahaar | 12.00 | 150 |
+-------+--------------------+-------+----------+

6 rows in set (0.00 sec)

Q.42.Display names and codes of those drinks that have more than 120 calories.

mysql> select Dcode, Dname from SoftDrink where Calories>120;


+-------+--------------------+
| DCODE | DNAME |
+-------+--------------------+
| 104 | Green Mango |
| 105 | Aam Panna |
| 106 | Mango Juice Bahaar |
+-------+--------------------+
3 rows in set (0.00 sec)

Q.43.Display codes, names and calories of all drinks in descending order of


calories.

mysql> select Dcode, Dname, Calories from SoftDrink order by Calories desc;
+-------+--------------------+----------+
| DCODE | DNAME | Calories |
+-------+--------------------+----------+
| 106 | Mango Juice Bahaar | 150 |
| 104 | Green Mango | 140 |
| 105 | Aam Panna | 135 |
| 101 | Lime and Lemon | 120 |
| 102 | Apple Drink | 120 |
| 103 | Nature Nectar | 115 |
+-------+--------------------+----------+
6 rows in set (0.00 sec)
Q.44.Display names and price of drinks that have price in the range 12 to 18.

mysql> select Dname, Price from SoftDrink where Price>=12 and Price<=18;
+--------------------+-------+
| DNAME | PRICE |
+--------------------+-------+
| Apple Drink | 18.00 |
| Nature Nectar | 15.00 |
| Green Mango | 15.00 |
| Mango Juice Bahaar | 12.00 |
+--------------------+-------+
4 rows in set (0.00 sec)

Q.45. Increase the price of all drinks in the given table by 10%.

mysql> update SoftDrink set Price=Price+(Price*10/100);


Query OK, 6 rows affected (0.47 sec)
Rows matched: 6 Changed: 6 Warnings: 0

Q.46.Write a command to create a table named as Supplier.

mysql> create table Supplier(SCODE int(3), PNAME char(10), SUPNAME


char(20), QTY int(3), CITY char(15), PRICE decimal(4,2));
Query OK, 0 rows affected (0.53 sec)

mysql> insert into Supplier values(101,'Coffee','Nestle',200,'Kolkata',55.00);


Query OK, 1 row affected (0.08 sec)

mysql> insert into Supplier values(102,'Biscuit','Hide & Seek',100,'Delhi',10.00);


Query OK, 1 row affected (0.14 sec)

mysql> insert into Supplier values(103,'Jam','Kissan',110,'Kolkata',25.00);


Query OK, 1 row affected (0.09 sec)

mysql> insert into Supplier values(104,'Maggi','Nestle',150,'Mumbai',10.00);


Query OK, 1 row affected (0.13 sec)

mysql> insert into Supplier values(105,'Chocolate','Cadbury',170,'Delhi',25.00);


Query OK, 1 row affected (0.09 sec)

mysql> insert into Supplier values(106,'Sauce','Maggi',56,'Mumbai',55.00);


Query OK, 1 row affected (0.11 sec)
mysql> insert into Supplier values(107,'Cake','Britania',72,'Delhi',10.00);
Query OK, 1 row affected (0.12 sec)

mysql> select *from Supplier;


+-------+-----------+-------------+------+---------+-------+
| SCODE | PNAME | SUPNAME | QTY | CITY |
PRICE |
+-------+-----------+-------------+------+---------+-------+
| 101 | Coffee | Nestle | 200 | Kolkata | 55.00 |
| 102 | Biscuit | Hide & Seek | 100 | Delhi | 10.00 |
| 103 | Jam | Kissan | 110 | Kolkata | 25.00 |
| 104 | Maggi | Nestle | 150 | Mumbai | 10.00 |
| 105 | Chocolate | Cadbury | 170 | Delhi | 25.00 |
| 106 | Sauce | Maggi | 56 | Mumbai | 55.00 |
| 107 | Cake | Britania | 72 | Delhi | 10.00
|
+-------+-----------+-------------+------+---------+-------+
7 rows in set (0.00 sec).

Q.47.Display names of Products whose Pname starts with 'B' in ascending of


Price.

mysql> select Pname from Supplier where Pname like 'B%' order by price asc;

+---------+
| Pname |
+---------+
| Biscuit |
+---------+

1 row in set (0.00 sec)

Q.48.Display Supplier code, Product Name and city of the products whose
quantity is less than 150.

mysql> select Scode, Pname, City from Supplier where Qty<150;

+-------+---------+---------+
| Scode | Pname | City |
+-------+---------+---------+
| 102 | Biscuit | Delhi |
| 103 | Jam | Kolkata |
| 106 | Sauce | Mumbai |
| 107 | Cake | Delhi |
+-------+---------+---------+

4 rows in set (0.00 sec)

Q.49. To count distinct city in the table.

mysql> select distinct(City) from Supplier;


+---------+
| City |
+---------+
| Kolkata |
| Delhi |
| Mumbai |
+---------+
3 rows in set (0.08 sec)

Q.50. To insert a new row in the table Supplier which is:


'110', 'Bournvita', 'ABC', 170, 'Delhi', 40.00.

mysql> insert into Supplier values(110,'Bournvita','ABC',170,'Delhi',40.00);


Query OK, 1 row affected (0.13 sec)

Q.51. Write a command to create a table named as SBOP.

mysql> create table SBOP(Accountno varchar(5), Name char(15), Balance


decimal(7,2), DateOfOpen date, Transaction int(2));
Query OK, 0 rows affected (0.74 sec)

mysql> insert into SBOP values('SB-1','Mr. Anil',15000.00,'2011-02-24',7);


Query OK, 1 row affected (0.17 sec)

mysql> insert into SBOP values('SB-2','Mr. Amit',23567.89,NULL,8);


Query OK, 1 row affected (0.13 sec)
mysql> insert into SBOP values('SB-3','Mrs. Sakshi',45000.00,'2012-02-04',5);
Query OK, 1 row affected (0.11 sec)

mysql> insert into SBOP values('SB-4','Mr. Gopal',23812.35,'2013-09-


22',NULL);
Query OK, 1 row affected (0.30 sec)

mysql> insert into SBOP values('SB-5','Mr. Dennis',63459.80,'2009-11-10',15);


Query OK, 1 row affected (0.41 sec)

mysql> select *from SBOP;


+-----------+-------------+----------+------------+-------------+
| Accountno | Name | Balance | DateOfOpen | Transaction |
+-----------+-------------+----------+------------+-------------+
| SB-1 | Mr. Anil | 15000.00 | 2011-02-24 | 7
|
| SB-2 | Mr. Amit | 23567.89 | NULL | 8|
| SB-3 | Mrs. Sakshi | 45000.00 | 2012-02-04 | 5|
| SB-4 | Mr. Gopal | 23812.35 | 2013-09-22 | NULL |
| SB-5 | Mr. Dennis | 63459.80 | 2009-11-10 | 15 |
+-----------+-------------+----------+------------+-------------+
5 rows in set (0.00 sec)

Q.52. Display Accountno, Name and DateOfOpen of account holder having


transactions more than 8.

mysql> select AccountNo, Name, DateOfOpen from SBOP where Transaction>8;


+-----------+------------+------------+
| Accountno | Name | DateOfOpen |
+-----------+------------+------------+
| SB-5 | Mr. Dennis | 2009-11-10 |
+-----------+------------+------------+
1 row in set (0.02 sec)

Q.53. Display all information of account holders whose transaction value is not
mentioned.

mysql> select *from SBOP where Transaction is Null;


+-----------+-----------+----------+------------+-------------+
| Accountno | Name | Balance | DateOfOpen | Transaction |
+-----------+-----------+----------+------------+-------------+
| SB-4 | Mr. Gopal | 23812.35 | 2013-09-22 | NULL |
+-----------+-----------+----------+------------+-------------+
1 row in set (0.00 sec)

Q.54. Add another column Address with datatype and size as VARCHAR(25).

mysql> alter table SBOP add column Address Varchar(25);


Query OK, 0 rows affected (0.67 sec)
Records: 0 Duplicates: 0 Warnings: 0

Q.55. Display the month day with reference to DateOfOpen for all the account
holders.

mysql> select DayofMonth(DateOfOpen) "Day Of Month" from SBOP;


+--------------+
| Day Of Month |
+--------------+
| 24 |
| NULL |
| 4 |
| 22 |
| 10 |
+--------------+
5 rows in set (0.03 sec)

Q.56. Write a command to create a table named as EXAM.

mysql> create table Exam(Admn varchar(5), Sname char(15), Percentage


decimal(4,2), Clsec varchar(3), Stream char(15));
Query OK, 0 rows affected (0.91 sec)

mysql> insert into Exam values('R001','Sushant',90.2,'12A','Science');


Query OK, 1 row affected (0.10 sec)

mysql> insert into Exam values('R002','Vaidyanath',80.5,'12B','Humanities');


Query OK, 1 row affected (0.12 sec)

mysql> insert into Exam values('R003','Miara',68.9,'12B','Science');


Query OK, 1 row affected (0.09 sec)
mysql> insert into Exam values('R004','Niara',96.0,'12A','Commerce');
Query OK, 1 row affected (0.46 sec)

mysql> insert into Exam values('R005','Shinjini',88.9,'12D','Commerce');


Query OK, 1 row affected (0.07 sec)

mysql> select *from Exam;

+------+------------+------------+-------+------------+
| Admn | Sname | Percentage | Clsec | Stream |
+------+------------+------------+-------+------------+
| R001 | Sushant | 90.20 | 12A | Science |
| R002 | Vaidyanath | 80.50 | 12B | Humanities |
| R003 | Miara | 68.90 | 12B | Science |
| R004 | Niara | 96.00 | 12A | Commerce |
| R005 | Shinjini | 88.90 | 12D | Commerce |
+------+------------+------------+-------+------------+
5 rows in set (0.00 sec)

Q.57. Display all information of the students of humanities in descending order of


percentage.

mysql> select *from Exam where Stream='Humanities' order by Percentage desc;


+------+------------+------------+-------+------------+
| Admn | Sname | Percentage | Clsec | Stream |
+------+------------+------------+-------+------------+
| R002 | Vaidyanath | 80.50 | 12B | Humanities |
+------+------------+------------+-------+------------+
1 row in set (0.01 sec)

Q.58. Display Admn, Name, Percentage and Stream of those students whose
name is less than 6 characters.

mysql> select Admn, Sname, Percentage, Stream from Exam where


length(Sname)<6;
+------+-------+------------+----------+
| Admn | Sname | Percentage | Stream |
+------+-------+------------+----------+
| R003 | Miara | 68.90 | Science |
| R004 | Niara | 96.00 |Commerce |
+------+-------+------------+----------+
2 rows in set (0.03 sec)

Q.59. Add another column Bus_fees with datatype and size as Decimal(8,2).

mysql> alter table Exam add column Bus_Fees decimal(8,2);


Query OK, 0 rows affected (0.60 sec)
Records: 0 Duplicates: 0 Warnings: 0

Q.60. Increase percentage by 2% of all the Humanities Students.

mysql> update Exam set percentage=percentage+(percentage*2/100) where


Stream='Humanities';
Query OK, 1 row affected (0.15 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Q.61. Write a command to create a table named as STORE.

Query OK, 0 rows affected (0.96 sec)

mysql> insert into Store Values('S101', 'Planet Fashion', 'Karol Bagh', 'Delhi', 7,
'2015-10-16', 300000);
Query OK, 1 row affected (0.20 sec)

mysql> insert into Store Values('S102', 'Trends', 'Nehru Nagar', 'Mumbai', 11,
'2015-08-09', 400000);
Query OK, 1 row affected (0.14 sec)

mysql> insert into Store Values('S103', 'Vogue', 'Vikas Vihar', 'Delhi', 10, '2015-
06-27', 200000);
Query OK, 1 row affected (0.43 sec)

mysql> insert into Store Values('S104', 'Super Fashion', 'Defence Colony', 'Delhi',
8, '2015-02-18', 450000);
Query OK, 1 row affected (0.16 sec)

mysql> insert into Store Values('S105', 'Rage', 'Bandra', 'Mumbai', 5, '2015-09-


22', 600000);
Query OK, 1 row affected (0.10 sec)

Q.62. Display name, location, city, sales amount of stores in descending order of
sales amount.
mysql> select name, location, city, Salesamt from Store order by SalesAmt desc;
+----------------+----------------+--------+----------+
| name | location | city | Salesamt |
+----------------+----------------+--------+----------+
| Rage | Bandra | Mumbai | 600000 |
| Super Fashion | Defence Colony | Delhi | 450000 |
| Trends | Nehru Nagar | Mumbai | 400000 |
| Planet Fashion | Karol Bagh | Delhi | 300000 |
| Vogue | Vikas Vihar | Delhi | 200000 |
+----------------+----------------+--------+----------+
5 rows in set (0.00 sec)

Q.63. Display names of stores along with sales amount of those stores that have
fashion anywhere in their Store Names.

mysql> select Name, SalesAmt from Store where Name like '%fashion%';
+----------------+----------+
| Name | SalesAmt |
+----------------+----------+
| Planet Fashion | 300000 |
| Super Fashion | 450000 |
+----------------+----------+
2 rows in set (0.00 sec)

Q.64. Display Store Names, Location and Date Opened of store that were opened
before 1st March, 2015.

mysql> select Name, Location, DateOpened from Store where


DateOpened<'2015-03-01';
+---------------+----------------+------------+
| Name | Location | DateOpened |
+---------------+----------------+------------+
| Super Fashion | Defence Colony | 2015-02-18 |
+---------------+----------------+------------+
1 row in set (0.03 sec)

Q.65. Display Total sales amount of each city along with city name.

mysql> select sum(SalesAmt), city from Store group by City;


+---------------+--------+
| sum(SalesAmt) | city |
+---------------+--------+
| 950000 | Delhi |
| 1000000 | Mumbai |
+---------------+--------+
2 rows in set (0.03 sec)
Q.66. Write a command to create a table named as GYM.

mysql> create table Gym(Icode varchar(4), Iname char(25), Price int(6), Brand
char(15));
Query OK, 0 rows affected (0.48 sec)

mysql> insert into Gym values('G101','Power Fit Exerciser',20000,'Power


Gymea');
Query OK, 1 row affected (0.18 sec)

mysql> insert into Gym values('G102','Aquafit Hand Grip',1800,'Reliable');


Query OK, 1 row affected (0.47 sec)

mysql> insert into Gym values('G103','Cycle Bike',14000,'Ecobike');


Query OK, 1 row affected (0.12 sec)

mysql> insert into Gym values('G104','Protoner Extreme Gym',30000,'Coscore');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Gym values('G105','Message Belt',5000,'Message Expert');


Query OK, 1 row affected (0.08 sec)

mysql> insert into Gym values('G106','Cross Trainer',13000,'GTC Fitness');


Query OK, 1 row affected (0.12 sec)

mysql> select *from Gym;


+-------+----------------------+-------+----------------+
| Icode | Iname | Price | Brand |
+-------+----------------------+-------+----------------+
| G101 | Power Fit Exerciser | 20000 | Power Gymea |
| G102 | Aquafit Hand Grip | 1800 | Reliable |
| G103 | Cycle Bike | 14000 | Ecobike |
| G104 | Protoner Extreme Gym | 30000 | Coscore |
| G105 | Message Belt | 5000 | Message Expert |
| G106 | Cross Trainer | 13000 | GTC Fitness |
+-------+----------------------+-------+----------------+
6 rows in set (0.00 sec)
Q.67. Display the names of all the items whose name starts with 'A'.

mysql> select Iname from Gym where Iname like 'A%';


+-------------------+
| Iname |
+-------------------+
| Aquafit Hand Grip |
+-------------------+
1 row in set (0.00 sec)

Q.68. Display Icodes and Inames of all items whose Brand is Reliable or Coscore.

mysql> select Icode, Iname from Gym where Brand IN("Reliable","Coscore");


+-------+----------------------+
| Icode | Iname |
+-------+----------------------+
| G102 | Aquafit Hand Grip |
| G104 | Protoner Extreme Gym |
+-------+----------------------+
2 rows in set (0.02 sec)

Q.69. Change the Brand to “Fit Trend India” of the item whose Icode as “G101”.

mysql> update Gym set Brand='Fit Trend India' where Icode='G101';


Query OK, 1 row affected (0.14 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Q.70. Add new row for new item in Gym with deatils:
“G107”, “Vibro Exerciser”, 21000, “GTC
Fitness”

mysql> insert into Gym values('G107','Vibro Exerciser',21000,'GTC Fitness');


Query OK, 1 row affected (0.10 sec)

Q.71. Write a command to create a table named as FITNESS.

mysql> create table Fitness(Pcode varchar(2), Pname char(15), Price int(6),


Manufacturer char(10));
Query OK, 0 rows affected (0.85 sec)

mysql> insert into Fitness values('P1','Treadmill',21000,'Coscore');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Fitness values('P2','Bike',20000,'Aone');


Query OK, 1 row affected (0.14 sec)

mysql> insert into Fitness values('P3','Cross Trainer',14000,'Reliable');


Query OK, 1 row affected (0.40 sec)

mysql> insert into Fitness values('P4','Multi Gym',34000,'Coscore');


Query OK, 1 row affected (0.13 sec)

mysql> insert into Fitness values('P5','Massage Chair',5500,'Regrosene');


Query OK, 1 row affected (0.08 sec)

mysql> insert into Fitness values('P6','Belly Belt',6500,'Ambawya');


Query OK, 1 row affected (0.26 sec)

mysql> select *from Fitness;


+-------+---------------+-------+--------------+
| Pcode | Pname | Price | Manufacturer |
+-------+---------------+-------+--------------+
| P1 | Treadmill | 21000 | Coscore |
| P2 | Bike | 20000 | Aone |
| P3 | Cross Trainer | 14000 | Reliable |
| P4 | Multi Gym | 34000 | Coscore |
| P5 | Massage Chair | 5500 | Regrosene |
| P6 | Belly Belt | 6500 | Ambawya |
+-------+---------------+-------+--------------+
6 rows in set (0.00 sec)

Q.72. Display the names of all the products with price more than 20000.

mysql> select Pname from Fitness where Price>20000;


+-----------+
| Pname |
+-----------+
| Treadmill |
| Multi Gym |
+-----------+
2 rows in set (0.00 sec)
Q.73. Display the names of all products by the manufacturer “Aone”.

mysql> select *from Fitness where Manufacturer='Aone';


+-------+-------+-------+--------------+
| Pcode | Pname | Price | Manufacturer |
+-------+-------+-------+--------------+
| P2 | Bike | 20000 | Aone |
+-------+-------+-------+--------------+
1 row in set (0.00 sec)

Q.74. Change the price data of all the products by applying 25% discount.

mysql> update Fitness set Price=Price-(Price*25/100);


Query OK, 6 rows affected (0.15 sec)
Rows matched: 6 Changed: 6 Warnings: 0

Q.75. Add new row for product with the details:


“P7”, “Vibro Exerciser”, 28000, “Aone”.

mysql> insert into Fitness values('P7','Vibro Exerciser',28000,'Aone');


Query OK, 1 row affected (0.08 sec)

Q.76. Write a command to create a table named as SHOPPE.

mysql> create table Shoppe(Code int(3), Item char(10), Company char(15), Qty
int(3), City char(10), Price decimal(5,2));
Query OK, 0 rows affected (0.62 sec)

mysql> insert into Shoppe values(101,'Coffee','Nestle',200,'Kolkata',25.00);


Query OK, 1 row affected (0.16 sec)

mysql> insert into Shoppe values(102,'Biscuit','Hide & Seek',100,'Delhi',10.00);


Query OK, 1 row affected (0.15 sec)

mysql> insert into Shoppe values(103,'Jam','Kissan',110,'Kolkata',25.00);


Query OK, 1 row affected (0.08 sec)

mysql> insert into Shoppe values(104,'Maggi','Nestle',150,'Mumbai',10.00);


Query OK, 1 row affected (0.17 sec)

mysql> insert into Shoppe values(105,'Chocolate','Cadbury',170,'Delhi',25.00);


Query OK, 1 row affected (0.12 sec)

mysql> insert into Shoppe values(106,'Sauce','Maggi',56,'Mumbai',10.00);


Query OK, 1 row affected (0.14 sec)

mysql> insert into Shoppe values(107,'Cake','Britania',72,'Delhi',10.00);


Query OK, 1 row affected (0.37 sec)

mysql> select *from Shoppe;


+------+-----------+-------------+------+---------+-------+
| Code | Item | Company | Qty | City | Price |
+------+-----------+-------------+------+---------+-------+
| 101 | Coffee | Nestle | 200 | Kolkata | 25.00
|
| 102 | Biscuit | Hide & Seek | 100 | Delhi | 10.00 |
| 103 | Jam | Kissan | 110 | Kolkata | 25.00 |
| 104 | Maggi | Nestle | 150 | Mumbai | 10.00 |
| 105 | Chocolate | Cadbury | 170 | Delhi | 25.00 |
| 106 | Sauce | Maggi | 56 | Mumbai | 10.00 |
| 107 | Cake | Britania | 72 | Delhi | 10.00 |
+------+-----------+-------------+------+---------+-------+
7 rows in set (0.00 sec)

Q.77. Display names of the items whose name starts with 'C' in ascending order
of price

mysql> select Item from Shoppe where Item like 'C%' order by Price asc;
+-----------+
| Item |
+-----------+
| Cake |
| Coffee |
| Chocolate |
+-----------+
3 rows in set (0.00 sec)

Q.78. Display code, name and city of the products whose quantity is less than
100.

mysql> select Code, Item, City from Shoppe where Qty<100;


+------+-------+--------+
| Code | Item | City |
+------+-------+--------+
| 106 | Sauce | Mumbai |
| 107 | Cake | Delhi |
+------+-------+--------+
2 rows in set (0.00 sec)

Q.79. Count Distinct Company from the table.

mysql> select count( distinct( Company )) "Distinct Company Count" from


Shoppe;
+------------------------+
| Distinct Company Count |
+------------------------+
| 6 |
+------------------------+
1 row in set (0.00 sec)

Q.80. Insert a new row in the table Shoppe:


'110', 'Pizza', 'Papa Jones', '120', 'Kolkata', '50.00'.

mysql> insert into Shoppe values(110,'Pizza','Papa Jones',120,'Kolkata',50.00);


Query OK, 1 row affected (0.26 sec)

Q.81. Write a command to create a table named as RESULT.

mysql> create table Result(No int(2), Name char(10), Stipend int(3), Subject
char(15), Average int(2), Division char(10));
Query OK, 0 rows affected (0.47 sec)

mysql> insert into Result values(1,'Sharon',400,'English',38,'Third');


Query OK, 1 row affected (0.30 sec)

mysql> insert into Result values(2,'Amal',680,'Mathematics',72,'First');


Query OK, 1 row affected (0.11 sec)

mysql> insert into Result values(3,'Vedant',500,'Accounts',67,'First');


Query OK, 1 row affected (0.09 sec)

mysql> insert into Result values(4,'Shakeer',200,'Informatics',55,'Second');


Query OK, 1 row affected (0.20 sec)

mysql> insert into Result values(5,'Anandha',400,'History',85,'First');


Query OK, 1 row affected (0.13 sec)

mysql> insert into Result values(6,'Upansna',550,'Geography',45,'Third');


Query OK, 1 row affected (0.23 sec)

mysql> select *from Result;

+------+---------+---------+-------------+---------+----------+
| No | Name | Stipend | Subject | Average | Division |
+------+---------+---------+-------------+---------+----------+
| 1 | Sharon | 400 | English | 38 | Third |
| 2| Amal | 680 | Mathematics | 72 | First
|
| 3 | Vedant | 500 | Accounts | 67 | First
|
| 4 | Shakeer | 200 | Informatics | 55 | Second |
| 5 | Anandha | 400 | History | 85 | First |
| 6 | Upansna | 550 | Geography | 45 | Third |
+------+---------+---------+-------------+---------+----------+

6 rows in set (0.00 sec)

Q.82. List the names of those students who have obtained Division as First in the
ascending order of the names.

mysql> select Name from Result where Division='First' order by Name asc;

+---------+
| Name |
+---------+
| Amal |
| Anandha |
| Vedant |
+---------+

3 rows in set (0.03 sec)


Q.83. Display a report listng Name, Subject and Annual Stipend received
assuming that the stipend column has monthly stipend.

mysql> select Name,Subject,Stipend*12 "Annual Stipend" from Result;


+---------+-------------+----------------+
| Name | Subject | Annual Stipend |
+---------+-------------+----------------+
| Sharon | English | 4800 |
| Amal | Mathematics | 8160 |
| Vedant | Accounts | 6000 |
| Shakeer | Informatics | 2400 |
| Anandha | History | 4800 |
| Upansna | Geography | 6600 |
+---------+-------------+----------------+
6 rows in set (0.00 sec)

Q.84. Count the number of students who have either Accounts or Informatics as
Subject.

mysql> select Count(Name) from Result where Subject='Accounts' or


Subject='Informatics';
+-------------+
| Count(Name) |
+-------------+
| 2 |
+-------------+
1 row in set (0.00 sec)

Q.85. Insert a new row in the table Result.


'7', 'Mohan', '500', 'English', '73', 'Second'.

mysql> insert into Result values(7,'Mohan',500,'English',73,'Second');


Query OK, 1 row affected (0.11 sec)
CONCLUSIO
N
A project from the part of a student can be
purposeful learning activity including
practical problems planned and carried out
in real life manner to achieve specific
goals. This project is successful to
complete the IP Practical by taking some of
the problems. It has encouraged me to think
and act together which is necessary to
acheive the given target. In the process also
developed mutual cooperation and team
spirit.

You might also like