Você está na página 1de 17

mysql> Use Practical_Work1;

Database changed

mysql> Create Table Shoes

->

-> (Code Char(4),

-> Name Varchar(20),

-> Type Varchar(10),

-> Size Int(2),

-> Cost Decimal(6,2),

-> Margin Decimal(4,2),

-> Qty Int(4),

-> Primary Key(Code));

Query OK, 0 rows affected (0.17 sec)

mysql> Describe Shoes;

+--------+--------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+--------+--------------+------+-----+---------+-------+

| Code | char(4) | NO | PRI | | |

| Name | varchar(20) | YES | | NULL | |

| Type | varchar(10) | YES | | NULL | |

| Size | int(2) | YES | | NULL | |

| Cost | decimal(6,2) | YES | | NULL | |

| Margin | decimal(4,2) | YES | | NULL | |

| Qty | int(4) | YES | | NULL | |


+--------+--------------+------+-----+---------+-------+

7 rows in set (0.02 sec)

mysql> Insert into Shoes Values("1001","School Canvas","School",6,132.50,2,1200);

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Shoes Values("1002","School Canvas","School",7,135.50,2,800);

Query OK, 1 row affected (0.28 sec)

mysql> Insert into Shoes Values("1003","School Canvas","School",8,140.75,2,600);

Query OK, 1 row affected (0.06 sec)

mysql> Insert into Shoes Values("1011","School Leather","School",6,232.50,2,2200);

Query OK, 1 row affected (0.06 sec)

mysql> Insert into Shoes Values("1012","School Leather","School",7,270.00,2,1280);

Query OK, 1 row affected (0.38 sec)

mysql> Insert into Shoes Values("1013","School Leather","School",8,320.75,NULL,1100);

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Shoes Values("1101","Galaxy","Office",7,640.00,3,200);

Query OK, 1 row affected (0.37 sec)

mysql> Insert into Shoes Values("1102","Galaxy","Office",8,712.00,3,500);


Query OK, 1 row affected (0.05 sec)

mysql> Insert into Shoes Values("1103","Galaxy","Office",9,720.00,3,400);

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Shoes Values("1201","Tracker","Sports",6,700.00,NULL,280);

Query OK, 1 row affected (0.38 sec)

mysql> Insert into Shoes Values("1202","Tracker","Sports",7,745.25,3.50,NULL);

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Shoes Values("1203","Tracker","Sports",8,800.50,3.50,600);

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Shoes Values("1204","Tracker","Sports",9,843.00,NULL,860);

Query OK, 1 row affected (0.20 sec)

mysql> Select * From Shoes;

+------+----------------+--------+------+--------+--------+------+

| Code | Name | Type | Size | Cost | Margin | Qty |

+------+----------------+--------+------+--------+--------+------+

| 1001 | School Canvas | School | 6 | 132.50 | 2.00 | 1200 |

| 1002 | School Canvas | School | 7 | 135.50 | 2.00 | 800 |

| 1003 | School Canvas | School | 8 | 140.75 | 2.00 | 600 |

| 1011 | School Leather | School | 6 | 232.50 | 2.00 | 2200 |

| 1012 | School Leather | School | 7 | 270.00 | 2.00 | 1280 |


| 1013 | School Leather | School | 8 | 320.75 | NULL | 1100 |

| 1101 | Galaxy | Office | 7 | 640.00 | 3.00 | 200 |

| 1102 | Galaxy | Office | 8 | 712.00 | 3.00 | 500 |

| 1103 | Galaxy | Office | 9 | 720.00 | 3.00 | 400 |

| 1201 | Tracker | Sports | 6 | 700.00 | NULL | 280 |

| 1202 | Tracker | Sports | 7 | 745.25 | 3.50 | NULL |

| 1203 | Tracker | Sports | 8 | 800.50 | 3.50 | 600 |

| 1204 | Tracker | Sports | 9 | 843.00 | NULL | 860 |

+------+----------------+--------+------+--------+--------+------+

13 rows in set (0.00 sec)

mysql> Select * From Shoes Where Qty>1200 and qty<2000;

+------+----------------+--------+------+--------+--------+------+

| Code | Name | Type | Size | Cost | Margin | Qty |

+------+----------------+--------+------+--------+--------+------+

| 1012 | School Leather | School | 7 | 270.00 | 2.00 | 1280 |

+------+----------------+--------+------+--------+--------+------+

1 row in set (0.05 sec)

mysql> Select Name From Shoes Where Size>=7;

+----------------+

| Name |

+----------------+

| School Canvas |

| School Canvas |
| School Leather |

| School Leather |

| Galaxy |

| Galaxy |

| Galaxy |

| Tracker |

| Tracker |

| Tracker |

+----------------+

10 rows in set (0.00 sec)

mysql> Select Cost+Cost*Margin/100 As "Final Price" From Shoes;

+--------------+

| Final Price |

+--------------+

| 135.15000000 |

| 138.21000000 |

| 143.56500000 |

| 237.15000000 |

| 275.40000000 |

| NULL |

| 659.20000000 |

| 733.36000000 |

| 741.60000000 |

| NULL |
| 771.33375000 |

| 828.51750000 |

| NULL |

+--------------+

13 rows in set (0.06 sec)

+--------------+

| Final Price |

+--------------+

| 135.15000000 |

| 138.21000000 |

| 143.56500000 |

| 237.15000000 |

| 275.40000000 |

| NULL |

| 659.20000000 |

| 733.36000000 |

| 741.60000000 |

| NULL |

| 771.33375000 |

| 828.51750000 |

| NULL |

+--------------+

13 rows in set (0.06 sec)

mysql> Select * From Shoes Where Name Like "%S%";

+------+----------------+--------+------+--------+--------+------+
| Code | Name | Type | Size | Cost | Margin | Qty |

+------+----------------+--------+------+--------+--------+------+

| 1001 | School Canvas | School | 6 | 132.50 | 2.00 | 1200 |

| 1002 | School Canvas | School | 7 | 135.50 | 2.00 | 800 |

| 1003 | School Canvas | School | 8 | 140.75 | 2.00 | 600 |

| 1011 | School Leather | School | 6 | 232.50 | 2.00 | 2200 |

| 1012 | School Leather | School | 7 | 270.00 | 2.00 | 1280 |

| 1013 | School Leather | School | 8 | 320.75 | NULL | 1100 |

+------+----------------+--------+------+--------+--------+------+

6 rows in set (0.00 sec)

mysql> Update Shoes Set Margin=4.50 Where Code="1001";

Query OK, 1 row affected (0.13 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> Select * From Shoes Where Code="1001";

+------+---------------+--------+------+--------+--------+------+

| Code | Name | Type | Size | Cost | Margin | Qty |

+------+---------------+--------+------+--------+--------+------+

| 1001 | School Canvas | School | 6 | 132.50 | 4.50 | 1200 |

+------+---------------+--------+------+--------+--------+------+

1 row in set (0.00 sec)

mysql> Update Shoes Set Name="Jordans" Where Code="1204";

Query OK, 1 row affected (0.06 sec)

Rows matched: 1 Changed: 1 Warnings: 0


mysql> Select * From Shoes Where Code="1204";

+------+---------+--------+------+--------+--------+------+

| Code | Name | Type | Size | Cost | Margin | Qty |

+------+---------+--------+------+--------+--------+------+

| 1204 | Jordans | Sports | 9 | 843.00 | NULL | 860 |

+------+---------+--------+------+--------+--------+------+

1 row in set (0.00 sec)

mysql> Alter Table Shoes Add Rating Decimal(2,1) Not Null;

Query OK, 13 rows affected (0.50 sec)

Records: 13 Duplicates: 0 Warnings: 0

mysql> Describe Shoes;

+--------+--------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+--------+--------------+------+-----+---------+-------+

| Code | char(4) | NO | PRI | | |

| Name | varchar(20) | YES | | NULL | |

| Type | varchar(10) | YES | | NULL | |

| Size | int(2) | YES | | NULL | |

| Cost | decimal(6,2) | YES | | NULL | |

| Margin | decimal(4,2) | YES | | NULL | |

| Qty | int(4) | YES | | NULL | |

| Rating | decimal(2,1) | NO | | NULL | |

+--------+--------------+------+-----+---------+-------+
8 rows in set (0.05 sec)

mysql> Select Type,Sum(qty) As "Total Quantity" From Shoes Group By type;

+--------+----------------+

| Type | Total Quantity |

+--------+----------------+

| Office | 1100 |

| School | 7180 |

| Sports | 1740 |

+--------+----------------+

3 rows in set (0.00 sec)

mysql> Select Type,Min(margin) AS "Minimum Margin",

-> Max(margin) As "Maximum Margin",

-> Avg(margin) As "Average Margin" From Shoes Group BY type;

+--------+----------------+----------------+----------------+

| Type | Minimum Margin | Maximum Margin | Average Margin |

+--------+----------------+----------------+----------------+

| Office | 3.00 | 3.00 | 3.000000 |

| School | 2.00 | 4.50 | 2.500000 |

| Sports | 3.50 | 3.50 | 3.500000 |

+--------+----------------+----------------+----------------+

3 rows in set (0.02 sec)

mysql> Select Max(Cost) As "Maximum Cost" From Shoes;

+--------------+
| Maximum Cost |

+--------------+

| 843.00 |

+--------------+

1 row in set (0.00 sec)

mysql> Select Ucase(name),Lcase(Name) From Shoes;

+----------------+----------------+

| Ucase(name) | Lcase(Name) |

+----------------+----------------+

| SCHOOL CANVAS | school canvas |

| SCHOOL CANVAS | school canvas |

| SCHOOL CANVAS | school canvas |

| SCHOOL LEATHER | school leather |

| SCHOOL LEATHER | school leather |

| SCHOOL LEATHER | school leather |

| GALAXY | galaxy |

| GALAXY | galaxy |

| GALAXY | galaxy |

| TRACKER | tracker |

| TRACKER | tracker |

| TRACKER | tracker |

| JORDANS | jordans |

+----------------+----------------+

13 rows in set (0.00 sec)


mysql> Select Distinct Type From Shoes;

+--------+

| Type |

+--------+

| School |

| Office |

| Sports |

+--------+

3 rows in set (0.00 sec)

mysql> Select Name,Length(Name) as "No of Character" From Shoes;

+----------------+-----------------+

| Name | No of Character |

+----------------+-----------------+

| School Canvas | 13 |

| School Canvas | 13 |

| School Canvas | 13 |

| School Leather | 14 |

| School Leather | 14 |

| School Leather | 14 |

| Galaxy | 6|

| Galaxy | 6|

| Galaxy | 6|

| Tracker | 7|

| Tracker | 7|
| Tracker | 7|

| Jordans | 7|

+----------------+-----------------+

13 rows in set (0.00 sec)

mysql> Create Table Customer

-> (Cust_Code Char(4),

-> Name Varchar(30),

-> Address Varchar(50),

-> Phone Varchar(30),

-> Category Char(1),

-> Primary Key (Cust_Code));

Query OK, 0 rows affected (0.20 sec)

mysql> Insert into Customer values("C001","Ram Sharma","RajNagar,Bhopal","4543556"

-> ,"A");

Query OK, 1 row affected (0.09 sec)

mysql> Insert into Customer values("C001","Ram Sharma","RajNagar,Bhopal",NULL,"B");

ERROR 1062 (23000): Duplicate entry 'C001' for key 'PRIMARY'

mysql> Insert into Customer values("C002","Vikas Gupta","31,Mangal Bazar,Agra",NULL,"B");

Query OK, 1 row affected (0.09 sec)

mysql> Insert into Customer values("C003","Sidhartha Gupta","New Market,Saharanpur","51917142,

"> 7677888","B");

Query OK, 1 row affected (0.06 sec)


mysql> Insert into Customer values("C004","Harsh Yadav","JanakPuri,NewDelhi","6134432,

"> 98178989","A");

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Customer values("C005","Hemant Yadav","MohanNagar,Ghaziabad",NULL,"C");

Query OK, 1 row affected (0.06 sec)

mysql> Create Table Orders

-> (Order_no int(5),

-> Cust_code char(4),

-> Shoe_code Char(4),

-> Order_qty int(4),

-> Order_date date,

-> Target_date date,

-> Primary Key(Order_no));

Query OK, 0 rows affected (0.33 sec)

mysql> Insert into Orders values(1,"C001","1001",200,"2008-12-10","2008-12-15");

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Orders values(2,"C001","1002",200,"2008-12-10","2008-12-15");

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Orders values(3,"C003","1011",150,"2009-01-08","2009-01-13");

Query OK, 1 row affected (0.08 sec)


mysql> Insert into Orders values(4,"C002","1012",250,"2009-01-08","2009-01-13");

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Orders values(5,"C001","1011",400,"2009-01-10","2009-01-15");

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Orders values(6,"C002","1101",300,"2009-01-10","2009-01-15");

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Orders values(7,"C004","1201",200,"2009-01-10","2009-01-15");

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Orders values(8,"C005","1102",350,"2009-01-10","2009-01-15");

Query OK, 1 row affected (0.08 sec)

mysql> Insert into Orders values(9,"C001","1103",225,"2009-01-13","2009-01-18");

Query OK, 1 row affected (0.05 sec)

mysql> Insert into Orders values(10,"C002","1203",200,"2009-01-14","2009-01-19");

Query OK, 1 row affected (0.08 sec)

mysql> Select * From Orders;

+----------+-----------+-----------+-----------+------------+-------------+

| Order_no | Cust_code | Shoe_code | Order_qty | Order_date | Target_date |

+----------+-----------+-----------+-----------+------------+-------------+
| 1 | C001 | 1001 | 200 | 2008-12-10 | 2008-12-15 |

| 2 | C001 | 1002 | 200 | 2008-12-10 | 2008-12-15 |

| 3 | C003 | 1011 | 150 | 2009-01-08 | 2009-01-13 |

| 4 | C002 | 1012 | 250 | 2009-01-08 | 2009-01-13 |

| 5 | C001 | 1011 | 400 | 2009-01-10 | 2009-01-15 |

| 6 | C002 | 1101 | 300 | 2009-01-10 | 2009-01-15 |

| 7 | C004 | 1201 | 200 | 2009-01-10 | 2009-01-15 |

| 8 | C005 | 1102 | 350 | 2009-01-10 | 2009-01-15 |

| 9 | C001 | 1103 | 225 | 2009-01-13 | 2009-01-18 |

| 10 | C002 | 1203 | 200 | 2009-01-14 | 2009-01-19 |

+----------+-----------+-----------+-----------+------------+-------------+

10 rows in set (0.00 sec)

mysql> Select Customer.Name,Customer.Phone,Orders.Order_no From Orders,Customer

-> Where Customer.Cust_code=Orders.Cust_code;

+----------------+-----------+----------+

| Name | Phone | Order_no |

+----------------+-----------+----------+

| Yash Gupta | 941280080 | 1|

| Yash Gupta | 941280080 | 2|

| Vikas Aggarwal | 2767779 | 3|

| Nishant Garg | 2764444 | 4|

| Yash Gupta | 941280080 | 5|

| Nishant Garg | 2764444 | 6|

| Harsh Aggarwal | 27677791 | 7|


| Ram Sharma | 2872456 | 8|

| Yash Gupta | 941280080 | 9|

| Nishant Garg | 2764444 | 10 |

+----------------+-----------+----------+

10 rows in set (0.00 sec)

mysql> Select Orders.Order_no,Orders.Order_qty,Shoes.Name,Shoes.Cost From

-> Orders,Shoes Where Orders.Shoe_code=Shoes.Code;

+----------+-----------+----------------+--------+

| Order_no | Order_qty | Name | Cost |

+----------+-----------+----------------+--------+

| 1| 200 | School Canvas | 132.50 |

| 2| 200 | School Canvas | 135.50 |

| 3| 150 | School Leather | 232.50 |

| 4| 250 | School Leather | 270.00 |

| 5| 400 | School Leather | 232.50 |

| 6| 300 | Galaxy | 640.00 |

| 7| 200 | Tracker | 700.00 |

| 8| 350 | Galaxy | 712.00 |

| 9| 225 | Galaxy | 720.00 |

| 10 | 200 | Tracker | 800.50 |

+----------+-----------+----------------+--------+

10 rows in set (0.00 sec)

mysql> Select Orders.Order_no,Customer.Name,Orders.Order_qty*Shoes.Cost As "Total Cost"

-> From Orders,Shoes,Customer Where Orders.Cust_code=Customer.Cust_code and

-> Shoes.Code=Orders.Shoe_code;
+----------+----------------+------------+

| Order_no | Name | Total Cost |

+----------+----------------+------------+

| 1 | Yash Gupta | 26500.00 |

| 2 | Yash Gupta | 27100.00 |

| 3 | Vikas Aggarwal | 34875.00 |

| 4 | Nishant Garg | 67500.00 |

| 5 | Yash Gupta | 93000.00 |

| 6 | Nishant Garg | 192000.00 |

| 7 | Harsh Aggarwal | 140000.00 |

| 8 | Ram Sharma | 249200.00 |

| 9 | Yash Gupta | 162000.00 |

| 10 | Nishant Garg | 160100.00 |

+----------+----------------+------------+

10 rows in set (0.00 sec)

mysql>

Você também pode gostar