05 - Ritesh Dbms Assignment 1
05 - Ritesh Dbms Assignment 1
TABLE CREATION:
1st Table: STATE NAME
2. Write a query to display cname and ccity of all records, sort by ccity descending order.
(Ans) select c.cname, p.pname, s.sale, s.saledt from custt c, prodd p, sale_detail s where
c.c_id=s.c_id and p.p_id=s.p_id;
5. Write a query to display cname who has purchased pen.
(Ans) select c.cname from custt c, prodd p, sale_detail s where c.c_id=s.c_id and p.p_id=s.p_id
and p.pname='pen';
6. Write a query to display saledt, and total sale on the data labelled as sale of all items sold
after 01-sept-08.
(Ans) select s.saledt, p.pcost*s.sale amount from sale_detail s , prodd p where s.p_id=p.p_id
and saledt > '01-sep-08';
7. Write a query to display satedt and total sale on the data labelled as sale of all items other
than floppy.
(Ans) select s.saledt, p.pname, p.pcost*s.sale amount from sale_detail s, prodd p where
s.p_id=p.p_id and p.pname !='floppy';
10. Write a query to display cname and ccity of all the customers who lived in kolkata or
chennai.
(Ans) select pname, pcost from prodd where pcost between '5' and '25';
12. Write a query to display distinct cid and pid is p3 or sale date is 18-sept-08
(Ans) select distinct c_id , p_id ,saledt from sale_detail where p_id ='p3' or saledt = ('18-sep-08');
13. Write a query to display cname, pid, and saledt of all those customers whose cid is in c1 or
c2 or c4 or c5.
(Ans) select c.cname, s.p_id ,s.saledt from custt c, sale_detail s where c.c_id =s.c_id and c.c_id in
('c1','c2','c4','c5');
14. Write a query to display all cname which includes two ‘’a’’ in the name.
16. Write a query to display average value of product cost rounded to 2 nd decimal places.
(Ans) select p.pname , sum(s.sale) from prodd p, sale_detail s where p.p_id=s.p_id group by
p.pname order by p.pname desc;
18. Write a query to display pname, saledt and total amount collected for the product.
20. Write a query to display the pname, sale date and total amount collected on date wise sale
of pen and pencil. Arrange them in ascending order of total collected amount.
22. Write a query to display sale date and total sale date which was sold after “14-jil-08”.
(Ans) select saledt, sum(sale) from sale_detail group by saledt having saledt >'14-jul-08' order
by saledt;
23. Write a query to display the customer name who belongs to those places whose name is
having character I or p.
(Ans) select cname from custt where ccity like 'i%' union select cname from custt where ccity
like 'p%';
24. Write a query to display the customer name who belongs to a city whose name contains
character “c” and whose name contains character “a”.
(Ans) select cname from custt where cname like 'a%' intersect select cname from custt where
ccity like 'c%';
25. Write a query to display the customer name who does not belong to pune.
30. Write a query to display customer name in upper case, lower case and title case from custt
table where customer name=’pradip’.
32. Write a query to display the position of character m in the cname of the customer whose
name is “anumita”.
(Ans)
36. Write a query to display average value of product and round it to 2 nd decimal places.