Monday 22 April 2013

Create following table
Table name : cust_master
Fields: cust_no (p), name, address, city

Table name : product_master
Fields: pro_no (p), p_name, qty, saleprice, costprice

Table name : purchase
Fields: cust_no (f), pro_no (f), p_qty, amount

and solve following queries:
(A) List the name of all customer who purchase "computer"
(B) List the p_name, p_qty and amount of all product purchase by "yash"
(C) List the non-moving product_name
(D) List the cust_name who purchase product of more thatn Rs. 1000
Solution:
create table cust_master
(cust_no varchar2(6) primary key,
name varchar2(25),
adderss varchar2(50),
city varchar2(15));

create table product_master
(pro_no varchar2(6) primary key,
p_name varchar2(15),
qty number(4),
saleprice number,
costprice number);

create table purchase
(cust_no varchar2(6) references cust_master(cust_no),
pro_no varchar2(6) references product_master(pro_no),
p_qty number(4),
amount number);


(A) List the name of all customer who purchase "computer"
      select name from cust_master where cust_no in (select cust_no from purchase where 
      pro_no in (select pro_no from product_master where     p_name="computer"))

(B) List the p_name, p_qty and amount of all product purchase by "yash"
      select d.p_name, p.p_qty, p.amount from product_master d, purchase p where
      p.pro_no=d.pro_no and p.cust_no in (select cust_no from cust_master where name="yash")

(C) List the non-moving product_name
      select p_name from product_master where pro_no not in (select distinct pro_no from 
      purchase)

(D) List the cust_name who purchase product of more thatn Rs. 1000

       select name from cust_master where cust_no in (select cust_no from purchase 
       where amount>1000)

No comments:

Post a Comment