Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.95 KB | None | 0 0
  1. create schema dinning;
  2.  
  3.  
  4. create table Staff (
  5. EmId int not null auto_increment,
  6. Name varchar(100) not null,
  7. Salary decimal(8,2),
  8. constraint PK_Staff primary key (EmId)
  9. );
  10.  
  11. create table skills (
  12. SkillId int not null auto_increment,
  13. Name varchar(100) not null,
  14. constraint PK_Skills primary key (SkillId)
  15. );
  16.  
  17. create table StafSkills (
  18. EmId int not null,
  19. SkillId int not null,
  20. constraint PK_StaffSkills primary key (EmId , SkillId),
  21. constraint FK_StaffSkills_Staff foreign key (EmID)
  22. references staff(EmId),
  23. constraint FK_StaffSkills_Skills foreign key (SkillID)
  24. references skills(SkillId)
  25.  
  26.  
  27. );
  28.  
  29. create table Menus (
  30. MenuId int not null auto_increment,
  31. Description varchar(100) not null,
  32. Type Varchar(100) not null,
  33. constraint PK_Menus primary key (MenuId)
  34. );
  35.  
  36. create table Dish (
  37. DishId int not null auto_increment,
  38. name Varchar(50)  not null,
  39. Preptime int,
  40. constraint PK_Dish primary key(DishId)
  41. );
  42.  
  43. create table ingredients (
  44. IngId int not null auto_increment,
  45. name varchar(50) not null,
  46. constraint PK_IngId primary key(IngId)
  47. );
  48.  
  49. create table Dishingredients (
  50. DishId int not null,
  51. IngId int not null,
  52. constraint PK_Dishingredients primary key(DishId, IngId),
  53. constraint FK_Dishingredients_Dish foreign key (DishId) references Dish(DishId),
  54. constraint Fk_Dishingredients_ingredients foreign key (IngId) references ingredients(IngId)
  55. on delete cascade
  56. on update restrict
  57. );
  58.  
  59.  
  60. create table menudish1 (
  61. menuId int not null,
  62. DishId int not null,
  63. constraint PK_menudish1 primary key (menuId, DishId),
  64. constraint FK_menudish1_menus foreign key (menuId)
  65. references menus(menuId),
  66. constraint FK_menuDish1_Dish foreign key(DishId)
  67. references dish(DishId)
  68. );
  69.  
  70.  
  71. insert into dish(Name, Preptime)
  72. Values('Taco',15),
  73. ('Southwesteren Corn', 30),
  74. ('Kabsah',120),
  75. ('Koppah',80),
  76. ('Kushri',80);
  77.  
  78. Insert into ingredients(name)
  79. Values ('rice'),('chicken'),('onion'),('oil'),('macroni'),('Tomatoes'),('Spices'),('Cheese'),('bread'),('ground beef');
  80.  
  81. insert into dishingredients(DishId, IngId) values
  82. (1 , 8), (1,9),(1,3),(1,10),(2,1),(2,7),(2,2),(2,5),(2,6),
  83. (3,10),(3,3),(3,5),(3,6),(3,7),
  84. (5,1),(5,2),(5,3),(5,4),(5,5),(5,6),(5,7);
  85.  
  86. insert into menus(Descreprtion,type) Values
  87. ('Spice taco sandwitch' , 'Dinner'),
  88. ('Red Rice Witch Chicken', 'lunch'),
  89. ('Ground beef grilled with borgol', 'All'),
  90. ('White ric with chicken' , 'Launch');
  91.  
  92. insert into menudish(menuId , DishId) values
  93. (1,1),(1,2),
  94. (2,3),
  95. (3,4),(3,2),
  96. (4,5);
  97.  
  98. select * from Staff;
  99.  
  100. alter table Staff
  101. add column DOB date,
  102. add column supervisorId int,
  103. add constraint FK_staff_supervisor foreign key(supervisorId)
  104. references staff(EmId);
  105.  
  106. update Staff set dob = '1988-01-22' where EmId = 1;
  107. update staff set salary = 100000 where EmId = 4;
  108.  
  109. select staff.name, skills.name from staff
  110. join StafSkills on StafSkills.EmId = staff.EmId
  111. join Skills on StafSkills.SkillId = skills.SkillId
  112. where skills.name = 'Customer Relationship';
  113.  
  114.  
  115.  
  116.  
  117.  
  118. ===================================
  119.  
  120. select * from staff;
  121. insert into staff(name, Salary)
  122.  
  123. Values('Adeeb Al Shakhs', 100.50),
  124. ('Mohammed hisham',6000),
  125. ('Thamer Jawish',8000),
  126. ('Hamza Mohamad', 7000);
  127.  
  128. insert into skills(name)
  129. Values('Cheif'),
  130. ('Customer Relationship'),
  131. ('Desert expert');
  132. select* from skills;
  133.  
  134. insert into StafSkills(EmId, SkillId)
  135. Values(1,1), (1,2), (1,3),
  136. (2,1),(2,2), (3,2),(3,3),(4,1),(4,2);
  137.  
  138. select * from StafSkills;
  139.  
  140.  
  141. ==========================
  142.  
  143.  
  144.  
  145.  
  146. -- are there any products that cost more than $500?
  147. select * from product_t where ProductStandardPrice > 500;
  148.  
  149. -- what is the total quantity that was sold in orderline_t?
  150. select sum(OrderedQuantity) as 'total' from orderline_t;
  151.  
  152. -- how many times product 8 was sold?
  153. select count(OrderedQuantity) from orderline_t where ProductID= 8;
  154.  
  155. -- what is the averege of net value for the product and the price?
  156. select avg(ProductStandardPrice) from product_t;
  157.  
  158. -- what is the value of the most expensive product?
  159. select max(ProductStandardPrice) from product_t;
  160.  
  161. select * from product_t order by ProductStandardPrice desc limit 1;
  162.  
  163. -- whats the value of the lease expensive product?
  164. select min(ProductStandardPrice) as 'cheapeset' from product_t;
  165.  
  166. select * from product_t order by ProductStandardPrice asc limit 1;
  167.  
  168. -- provide an invoce that includes the product id and the descriptipon,
  169. -- name of the productline, and the quantity ordered for all products
  170. -- purchased by contemporary casuals on october 21st 2010.
  171.  
  172.  
  173.  
  174. select product_t.ProductID, product_t.ProductDescription,productline_t.ProductLineName,
  175.  orderline_t.OrderedQuantity, customer_t.CustomerName, order_t.OrderDate from customer_t
  176. join order_t on customer_t.CustomerID = order_t.CustomerID
  177.  
  178. join orderline_t on order_t.OrderID = orderline_t.OrderID
  179. join product_t on orderline_t.ProductID = product_t.ProductID
  180. join productline_t on product_t.ProductLineID = productline_t.ProductLineID
  181. where customer_t.CustomerName = 'Contemporary Casuals'
  182. and order_t.OrderDate= '2010-10-21';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement