DBMS Lab File
DBMS Lab File
DBMS Lab File
Query : Retrieve the list of names and cities of all the cities
mysql> select name, city from client_master;
| name | city |
| Ivan | Bombay |
| Vandana | Madras |
| Pramada | Bombay |
| Basu | Bombay |
| Ravi | Delhi |
| Rukmini | Bombay | 6 rows in set (0.00 sec)
Query : Find list of all clients who stay in city “Bombay” or “Delhi” or
“Madras”
mysql> select name from client_master where city in ("Delhi","Bombay","Madras");
| name |
Query : Find out clients who stay in city whose second letter is “a”
mysql> select city from client_master where city like "_a%";
| city |
| Madras | 1 row in set (0.00 sec)
mysql> select name from client_master where name like "_a%";
| name |
| Vandana |
| Basu |
| Ravi | 3 rows in set (0.00 sec)
Query: Delete the record with client 0001 from client_master table.
mysql> delete from client_master where client_no=0001;
Query OK, 1 row affected (0.00 sec)
Query: Add the not null constraint in product_master table with columns
description, profit_percent, sell_price and cost_price
mysql> alter table product_master modify Description varchar(15) not null, modify
profile_percent
decimal(2,0),modify sell_price decimal(6,0),modify cost_price decimal(6,0) not null;
Query OK, 4 rows affected (0.21 sec) Records: 4 Duplicates: 0 Warnings: 0
mysql> alter table client_master add constraint pk primary key(client_no);
Query OK, 5 rows affected (0.24 sec) Records: 5 Duplicates: 0 Warnings: 0
mysql> alter table product_master add constraint pk primary key(product_no);
Query OK, 4 rows affected (0.18 sec) Records: 4 Duplicates: 0 Warnings: 0
Query: Add the not null constraint in the product_master table with the
columns description, profit_percent, sell_price and cost_price
mysql> alter table product_master modify Description varchar(15) not null, modify
profile_percent
decimal(2,0),modify sell_price decimal(6,0),modify cost_price decimal(6,0) not null;
Query OK, 4 rows affected (0.21 sec) Records: 4 Duplicates: 0 Warnings: 0
Query : the order number,client name and day of week on which clients
placed their order.
mysql> select s_order_no,name,extract(day from s_order_date) from sales_order
s,client_master c where s.client_no= c.client_no;
| s_order_no | name | extract(day from s_order_date) |
| 010008 | Ravi | 24 |
| 016865 | Pramada | 18 |
| 019001 | Ivan | 12 |
| 019002 | Vandana | 25 |
| 019003 | Ivan | 3|
| 046866 | Basu | 20 |
Query: Display the month and date when the order must be delivered
and the name of the salesman to whom the order was placed.
mysql> select sal_name,extract(month from dely_date),dely_date from sales_master
p,sales_order where p.salesman_no=o.salesman_no;
| sal_name | extract(month from dely_date) | dely_date |
| kiran | 1 | 1996-01-20 |
Query: Find out the names of products that have been sold to “Ivan”.
mysql> select description from sales_order s,sales_order_details d,product_master
p,client_master c where s.s_order_no=d.s_order_no and d.product_no=p.product_no and
c.client_no=s.client_no and c.name='Ivan';
| description |
| 1.44floppies |
| CD Drive |
| 540 HDD |
| 1.44floppies |
| Monitors |
Query: For each sales order display the name of the client and the
salesman.
mysql> select name,sal_name from client_master c,sales_master s,sales_order t where
s.salesman_no=t.salesman_no and c.client_no=t.client_no;
| name | sal_name |
| Ivan | kiran |
| Ivan | kiran |
| Vandana | manish |
| Pramada | ravi |
| Ravi | ashish |
| Basu | ashish |
Query :Find out the names of clients who have purchased “CD DRIVE”.
mysql>select name from client_master c,product_master p,sales_order
s,sales_order_details d where c.client_no=s.client_no and s.s_order_no=d.s_order_no and
d.product_no=p.product_no and p.description='CD Drive';
Query:. Calculate the minimum sale price of the products. mysql> select
min(sell_price) from product_master;
| min(sell_price) |
| 525 |
Query: Determine the max and min cost price. Rename the title as ‘max
price’ and ‘min price’ .
mysql> select min(cost_price) as 'min price',max(cost_price) as 'max price' from
product_master;
| min price | max price |
| 500 | 11200 |
Query: Find out the product name and their quantities to be delivered.
mysql> select description,qty_order from product_master pm , sales_order_details sod
where pm.product_no = sod.product_no group by(description);
| description | qty_order |
| 1.44 Drive | 1|
| 1.44floppies | 4|
| CD Drive | 2|
| Keyboards | 3|
| Monitors | 2|
| Mouse | 1|
Query:. Find the product no and their quantities for orders placed by
client_no ‘0001’ and ‘0002’.
mysql> select product_no,qty_order from sales_order so, sales_order_details sod where
sod.s_order_no = so.s_order_no and (client_no='0001' or client_no = '0002');
| product_no | qty_order |
| p07885 | 2|
| p07965 | 2|
| p03453 | 2|
Query:. Find order no , client no. , and salesman no. where more than
one salesman has received a client.
mysql> select s_order_no , client_no , salesman_no from sales_order group
by(salesman_no) having(count(client_no)>1);
| s_order_no | client_no | salesman_no |
| o19002 | 0002 | 500001 |
| o19001 | 0001 | 500002 |
Query: Print the description and total quantity sold for each product.
mysql> select description , qty_disp from product_master pm , sales_order_details sod
where pm.product_no = sod.product_no;
| description | qty_disp |
| 1.44floppies | 4|
| Monitors | 2 | | Mouse | 1|
| Keyboards | 3|
| CD Drive | 1|
| 1.44 Drive | 0|
Query: Display the customer name, address, city and pincode for the
clients who live in the same city as ‘Basu’. Basu’s details should not be
displayed
mysql> select * from client_master where city=(select city from client_master where
name='Basu');
| client_no | name | city | state | pincode | bal_due | phone_no |
|3 | Pramada | Bombay | Maharastra | 400057 | 5000.00 | NULL |
|4 | Basu | Bombay | Maharastra | 400056 | 0.00 | NULL |
|5 | Ravi | Bombay | Delhi | 100001 | 2000.00 | NULL |
|6 | Rukmini | Bombay | Maharastra | 400050 | 0.00 | NULL |
4 rows in set (0.00 sec)
Query: Display the details of all the customers who live in the same city
and has the same balance due as ‘Basu’. Basu’s details should not be
displayed
mysql> select name from client_master where city=(select city from client_master where
name='Basu') and bal_due=(select bal_due from client_master where name='Basu');
| client_no | name | city | state | pincode | bal_due | phone_no |
|6 | Rukmini | Bombay | Maharastra | 400050 | 0.00 | NULL |
1 row in set (0.00 sec)
mysql> select * from product_master;
| product_no | Description | profile_percent | unit_measure | Qty_on_hand | Reorder_lvl |
sell_price | cost_price |
| P00001 | 1.44floppies | 5 | piece | 100 | 20 | 1150 | 500|
| P03453 | Monitors | 6 | piece | 10 | 3| 12000 | 11200 |
| P06734 | Mouse | 5 | piece | 20 | 5| 1050 | 500 |
| P07865 | 1.22floppies | 5 | piece | 100 | 20 | 525 | 500 |
Query: Display the names of client who have placed orders worth
Rs.10000 or more
mysql> select name from client_master,Sales_Order_Details, Sales_Order where
product_rate >10000 and client_master.client_no= Sales_Order.client_no and
Sales_Order.S_order_no=Sales_Order_Details.s_order_no;
Empty set (0.00 sec)
Query: Display the client names who have placed orders before any
orders placed by client_no ‘0003’
mysql> select c.name from client_master c, Sales_Order s where c.client_no=s.client_no
and s_order_date<(select s_order_date from Sales_Order where client_no=0003);
Empty set (0.00 sec)
mysql> select * from Sales_Master;
| salesman_no | sal_name | address | city | pincode | sal_amt | tgt_to_get | ytd_sales |
remarks | State |
| 500001 | Kiren | A/14 Worli | Bombay | 400002 | 3000.00 | 100.00 | 50.00 |
Good | Mah |
| 500002 | Manish | 64, Nariman | Bombay | 400002 | 3000.00 | 100.00 | 100.00 |
Good | Mah |
| 500003 | Ravi | P-7 Bandra | Bombay | 400032 | 3000.00 | 100.00 | 100.00 |
Good | Mah |
| 500004 | Ashish | A/5 Juhu | Bombay | 400044 | 3500.00 | 200.00 | 150.00 |
Good | Mah |
4 rows in set (0.00 sec)
Query: Select the client names from client_view who lives in city
‘Bombay’ mysql> select name_new from client_view where
city_new="Bombay";
| name_new |
| Pramada |
| Basu |
| Ravi |
| Rukmini |
4 rows in set (0.00 sec)