(Q Query) : Q.1. Create A Table Name As Student and Enter Any Six Records
(Q Query) : Q.1. Create A Table Name As Student and Enter Any Six Records
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(13, 7, 'Veena', 'Tennis', 'C', 'Cooking', 'A');
Query OK, 1 row affected (0.29 sec)
mysql> insert into student values(15, 10, 'Arpit', 'Cricket', 'A', 'Gardening', 'C');
Query OK, 1 row affected (0.27 sec)
Q.2. Display the names of the students who are getting a grade 'C' in either Game
or SUPW.
+-----------+-------+-------+---------+--------+-------------+--------+
| 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)
mysql> select Name, Supw from Student where Name like '%A';
+---------+------------+
| Name | Supw |
+---------+------------+
| Veena | Cooking |
| Archana | Literature |
+---------+------------+
2 rows in set (0.10 sec)
Q6. To show all information about the swimming coaches in the club.
Q.7. To list names of all coaches with their date of appointment in descending
order.
Q.8. To display a report showing CoachName, Pay , Age and bonus(15% on Pay)
for all the coaches.
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)
+------+---------+---------+-------------+---------+-------+-------+
| 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)
+------+---------+---------+-------------+---------+-------+-------+
| 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.
+---------+---------+--------------+
| 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)
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)
+------+------------------+-----------+------+----------+------+-------+
| 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.
Q.15. Display a list of all the books with Price more than 130 and sorted by Qty.
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)
+------+---------+---------+-------------+------+------+
| 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.
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)
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)
+------+----------+------+----------+------------+--------+------+
| 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.22. To list the names of female teachers who are in History Department.
+------+----------+------+---------+------------+--------+------+
| 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.
+------+----------+------+----------+------------+--------+------+
| 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.
+------------+--------+-----------+
| Lower Case | Normal | UpperCase |
+------------+--------+-----------+
| obama | Obama | OBAMA |
+------------+--------+-----------+
1 row in set (0.11 sec)
Q.30. Write a command to return left most and right most characters of the given
expression.
Q.31. Write a command to return all mathematical answers for two numbers 9
and 6.
+-------+-------+-------------+
| Power | Round | Square Root |
+-------+-------+-------------+
| 512 | 15.2 | 9|
+-------+-------+-------------+
1 row in set (0.07 sec)
Q.34. Write a command to return the day, month and year from the gien date.
Q.37.Display the names of those garments that are available in 'XL' size.
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 |
+-------+---------------+
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 |
+-------+------------+---------+
Q.42.Display names and codes of those drinks that have more than 120 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> select Pname from Supplier where Pname like 'B%' order by price asc;
+---------+
| Pname |
+---------+
| Biscuit |
+---------+
Q.48.Display Supplier code, Product Name and city of the products whose
quantity is less than 150.
+-------+---------+---------+
| Scode | Pname | City |
+-------+---------+---------+
| 102 | Biscuit | Delhi |
| 103 | Jam | Kolkata |
| 106 | Sauce | Mumbai |
| 107 | Cake | Delhi |
+-------+---------+---------+
Q.53. Display all information of account holders whose transaction value is not
mentioned.
Q.54. Add another column Address with datatype and size as VARCHAR(25).
Q.55. Display the month day with reference to DateOfOpen for all the account
holders.
+------+------------+------------+-------+------------+
| 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.58. Display Admn, Name, Percentage and Stream of those students whose
name is less than 6 characters.
Q.59. Add another column Bus_fees with datatype and size as Decimal(8,2).
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)
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.
Q.65. Display Total sales amount of each city along with city name.
mysql> create table Gym(Icode varchar(4), Iname char(25), Price int(6), Brand
char(15));
Query OK, 0 rows affected (0.48 sec)
Q.68. Display Icodes and Inames of all items whose Brand is Reliable or Coscore.
Q.69. Change the Brand to “Fit Trend India” of the item whose Icode as “G101”.
Q.70. Add new row for new item in Gym with deatils:
“G107”, “Vibro Exerciser”, 21000, “GTC
Fitness”
Q.72. Display the names of all the products with price more than 20000.
Q.74. Change the price data of all the products by applying 25% discount.
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)
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> 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)
+------+---------+---------+-------------+---------+----------+
| 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 |
+------+---------+---------+-------------+---------+----------+
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 |
+---------+
Q.84. Count the number of students who have either Accounts or Informatics as
Subject.