Advertisement
GamerBhai02

DBMS EXP 5

May 15th, 2025 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.27 KB | Source Code | 0 0
  1. create table customer(cust int,cname varchar(10), city varchar(10), primary key(cust));
  2. create table order1(ord int, odate date,cust int,ord_amt int,primary key(ord));
  3. create table item(item int, unit_price int, primary key(item));
  4. create table order_item(ord int REFERENCES order1(ord), item int REFERENCES item(item) on delete set null, qty int);
  5. create table warehouse(warehouse int, city varchar(15), primary key(warehouse));
  6. create table shipment(ord int REFERENCES order1(ord), warehouse int REFERENCES warehouse(warehouse), ship_date date);
  7. insert into customer(cust,cname,city) values
  8. (2,'shashi','N.America'),(3,'kala','U.S.A'),(5,'Dumini','India'),(2002,'Stuart','Switz'),
  9. (2003,'Binny','N.America'),(2004,'Curie','U.S.A'),(2005,'Dumini','India'),(2006,'Rick','India');
  10. insert into item(item,unit_price) values
  11. (1500,250),(750,167),(125,124),(136,420),(250,138),(10,500);
  12. insert into shipment(ord,warehouse,ship_date) values
  13. (1,322,'4-03-21'),(2,234,'7-12-23'),(3,324,'14-06-24'),
  14. (4,325,'12-10-25'),(5,326,'12-4-25');
  15. insert into order1(ord,odate,cust,ord_amt) values
  16. (1,'2006-10-5',2,5000),(2,'2006-10-8',3,2500),(3,'2006-10-9',3,1000),
  17. (4,'2006-10-6',5,1000),(5,'2006-11-3',1,5000);
  18. insert into order_item(ord,item,qty) values
  19. (1,1500,1),(1,750,1),(2,125,1),(3,136,5),(4,250,2),(4,10,2);
  20. insert into warehouse(warehouse,city) values
  21. (321,'Bangalore'),(322,'Hyderabad'),(323,'Bangalore'),(324,'New Delhi'),(325,'New York');
  22. select c.cname, count(*) as no_of_orders, avg(o.ord_amt) as avg_order_amt from customer c,order1 o where c.cust=o.cust group by c.cname;
  23. select ord from warehouse w,shipment s where w.warehouse=s.warehouse and city="New Delhi";
  24. delete from item where item=250;
  25. select * from order_item;
  26.  
  27. Output:
  28.  
  29. +--------+--------------+---------------+
  30. | cname  | no_of_orders | avg_order_amt |
  31. +--------+--------------+---------------+
  32. | shashi |            1 |     5000.0000 |
  33. | kala   |            2 |     1750.0000 |
  34. | Dumini |            1 |     1000.0000 |
  35. +--------+--------------+---------------+
  36. +------+
  37. | ord  |
  38. +------+
  39. |    3 |
  40. +------+
  41. +------+------+------+
  42. | ord  | item | qty  |
  43. +------+------+------+
  44. |    1 | 1500 |    1 |
  45. |    1 |  750 |    1 |
  46. |    2 |  125 |    1 |
  47. |    3 |  136 |    5 |
  48. |    4 |   10 |    2 |
  49. +------+------+------+
Tags: EXP 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement