Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Practical - 5 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Solve the following queries using sub queries:-

1) Find the product_no and description of non moving products i.e. product
not being sold.

select product_no ,description from product_master_2 where product_no


not in (select product_no from sales_order_details);

2) Find the customer name, address1, address2, city and pincode for the
client who has placed order no ‘O1901’.

select name,city,pincode from client_master_2 where client_no in (select


client_no from sales_order_2 where order_no = 'O1901' );

3) Find out if the product ‘Mouse’ has been ordered by any client and print
the client_no, name to whom it was sold.

select Client_no,Name from Client_master_2 where Client_no in(select


Client_no from Sales_order_2 where order_no in (select order_no from

1
sales_order_details where product_no in (select product_no from
product_master_2 where description ='mouse')));

Queries using Having and Group By Clause:

1) Print the description and total qty sold for each product.

select description, sum(Qty_disp) from sales_order_details,


product_master_2 group by description;

2) Find the value of each product sold.

select description, sum(qty_disp*product_rate) from product_master_2,


sales_order_details where
product_master_2.product_no=sales_order_details.product_no group by
description;

2
3) Find out the sum total of all the billed orders for the month of January.

select so.order_no,so.order_date,sum(sod.Qty_ordered *
sod.product_rate) 'Order Billed' from sales_order_2
so,sales_order_details sod where sod.order_no=so.order_no and
month(Order_date)=1 group by so.order_no;

Queries on Joins and Correlation:

1) Find out the products, which have been sold to ‘Ivan’.

select distinct p.product_no,p.description from product_master_2 as p


,sales_order_details as sod,sales_order as s,client_master_2 as c where
p.product_no=sod.product_no and sod.order_no=s.order_no and
s.client_no=c.client_no and c.name='Ivan';

3
2) Find the product_no and description of constantly sold i.e. rapidly moving
products.

select distinct p.product_no,p.description from product_master_2 as p


,sales_order_details as sod where p.product_no=sod.product_no;

3) Find the names of clients who have purchased ‘Cd Drive’.

select c.name,p.description from product_master_2 as p


,sales_order_details as sod,sales_order_2 as s,client_master_2 as c where
p.product_no=sod.product_no and sod.order_no=s.order_no and
s.client_no=c.client_no and p.description='Cd drive';

4
4) List the product number and order number from customers who have
ordered less than 4 units of 'Mouse'.

select distinct sod.product_no,sod.order_no from product_master_2 as p,


sales_order_details as sod,sales_order_2 as s where
sod.product_no=p.product_no and sod.qty_ordered<4 and
p.description='Mouse';

Queries on Constructing Sentences with data:

1) Print information from product-master, sales_order_detail tables in the


following format for all records:- {description} Worth Rs. {total sales for
the product} was sold.

select concat(P.description, 'Worth Rs', sum(s.qty_disp * s.product_rate))


from product_master_2 p,sales_order_details s where
p.product_no=s.product_no group by p.description;

5
6

You might also like