diff --git a/19UCS081_SHRUTI_A5.docx b/19UCS081_SHRUTI_A5.docx new file mode 100644 index 0000000..e39ba62 Binary files /dev/null and b/19UCS081_SHRUTI_A5.docx differ diff --git a/19UCS081_SHRUTI_A5.txt b/19UCS081_SHRUTI_A5.txt new file mode 100644 index 0000000..3b3a8ab --- /dev/null +++ b/19UCS081_SHRUTI_A5.txt @@ -0,0 +1,183 @@ + +-- 19UCS081 +-- SHRUTI GOYAL + + + +create database coffee_store; +use coffee_store; +create table products( + productID int primary key auto_increment, + Name varchar(30), + Price decimal(3,2), + CoffeeOrigin varchar(30) +); +create table customers( + customerID int primary key auto_increment, + First_Name varchar(30), + Last_Name varchar(30), + Gender enum('M','F'), + ContactNumber decimal(11,0) +); +create table orders( + orderID int primary key auto_increment, + productID int, + customerID int, + Date_Time datetime, + constraint FK_ProductOrder + foreign key (productID) references products(productID), + constraint FK_CustomerOrder + foreign key (customerID) references customers(customerID) +); + + +insert into products (Name,Price,CoffeeOrigin) +values +('Espresso', 2.50, 'Brazil'), +('Machhiato', 3.00, 'Brazil'), +('Cappuccino', 3.50, 'CostaRica'), +('Latte', 3.50, 'Indonesia'), +('Americano', 3.00, 'Brazil'), +('Flat White', 3.50, 'Brazil'), +('Filter', 3.00, 'India'); + +INSERT INTO customers (First_Name, Last_Name, Gender, ContactNumber) VALUES ('Chris','Martin','M','01123147789'),('Emma','Law','F','01123439899'),('Mark','Watkins','M','01174592013'),('Daniel','Williams','M',NULL),('Sarah','Taylor','F','01176348290'),('Katie','Armstrong','F','01145787353'),('Michael','Bluth','M','01980289282'),('Kat','Nash','F','01176987789'),('Buster','Bluth','M','01173456782'),('Charlie',NULL,'F','01139287883'),('Lindsay','Bluth','F','01176923804'),('Harry','Johnson','M',NULL),('John','Smith','M','01174987221'),('John','Taylor','M',NULL),('Emma','Smith','F','01176984116'),('Gob','Bluth','M','01176985498'),('George','Bluth','M','01176984303'),('Lucille','Bluth','F','01198773214'),('George','Evans','M','01174502933'),('Emily','Simmonds','F','01899284352'),('John','Smith','M','01144473330'),('Jennifer',NULL,'F',NULL),('Toby','West','M','01176009822'),('Paul','Edmonds','M','01966947113'); +INSERT INTO orders (productID,customerID,Date_Time) VALUES (1,1,'2017-01-01 08-02-11'),(1,2,'2017-01-01 08-05-16'),(5,12,'2017-01-01 08-44-34'),(3,4,'2017-01-01 09-20-02'),(1,9,'2017-01-01 11-51-56'),(6,22,'2017-01-01 13-07-10'),(1,1,'2017-01-02 08-03-41'),(3,10,'2017-01-02 09-15-22'),(2,2,'2017-01-02 10-10-10'),(3,13,'2017-01-02 12-07-23'),(1,1,'2017-01-03 08-13-50'),(7,16,'2017-01-03 08-47-09'),(6,21,'2017-01-03 09-12-11'),(5,22,'2017-01-03 11-05-33'),(4,3,'2017-01-03 11-08-55'),(3,11,'2017-01-03 12-02-14'),(2,23,'2017-01-03 13-41-22'),(1,1,'2017-01-04 08-08-56'),(3,10,'2017-01-04 11-23-43'),(4,12,'2017-01-05 08-30-09'),(7,1,'2017-01-06 09-02-47'),(3,18,'2017-01-06 13-23-34'),(2,16,'2017-01-07 09-12-39'),(2,14,'2017-01-07 11-24-15'),(4,5,'2017-01-08 08-54-11'),(1,1,'2017-01-09 08-03-11'),(6,20,'2017-01-10 10-34-12'),(3,3,'2017-01-10 11-02-11'),(4,24,'2017-01-11 08-39-11'),(4,8,'2017-01-12 13-20-13'),(1,1,'2017-01-14 08-27-10'),(4,15,'2017-01-15 08-30-56'),(1,7,'2017-01-16 10-02-11'),(2,10,'2017-01-17 09-50-05'),(1,1,'2017-01-18 08-22-55'),(3,9,'2017-01-19 09-00-19'),(7,11,'2017-01-19 11-33-00'),(6,12,'2017-01-20 08-02-21'),(3,14,'2017-01-21 09-45-50'),(5,2,'2017-01-22 10-10-34'),(6,24,'2017-01-23 08-32-19'),(6,22,'2017-01-23 08-45-12'),(6,17,'2017-01-23 12-45-30'),(2,11,'2017-01-24 08-01-27'),(1,1,'2017-01-25 08-05-13'),(6,11,'2017-01-26 10-49-10'),(7,3,'2017-01-27 09-23-57'),(7,1,'2017-01-27 10-08-16'),(3,18,'2017-01-27 10-13-09'),(4,19,'2017-01-27 11-02-40'),(3,10,'2017-01-28 08-03-21'),(1,2,'2017-01-28 08-33-28'),(1,12,'2017-01-28 11-55-33'),(1,13,'2017-01-29 09-10-17'),(6,6,'2017-01-30 10-07-13'),(1,1,'2017-02-01 08-10-14'),(2,14,'2017-02-02 10-02-11'),(7,10,'2017-02-02 09-43-17'),(7,20,'2017-02-03 08-33-49'),(4,21,'2017-02-04 09-31-01'),(5,22,'2017-02-05 09-07-10'),(3,23,'2017-02-06 08-15-10'),(2,24,'2017-02-07 08-27-26'),(1,1,'2017-02-07 08-45-10'),(6,11,'2017-02-08 10-37-10'),(3,13,'2017-02-09 08-58-18'),(3,14,'2017-02-10 09-12-40'),(5,4,'2017-02-10 11-05-34'),(1,2,'2017-02-11 08-00-38'),(3,8,'2017-02-12 08-08-08'),(7,20,'2017-02-12 09-22-10'),(1,1,'2017-02-13 08-37-45'),(5,2,'2017-02-13 12-34-56'),(4,3,'2017-02-14 08-22-43'),(5,4,'2017-02-14 09-12-56'),(3,5,'2017-02-15 08-09-10'),(6,7,'2017-02-15 09-05-12'),(1,8,'2017-02-15 09-27-50'),(2,9,'2017-02-16 08-51-12'),(3,10,'2017-02-16 13-07-46'),(4,11,'2017-02-17 08-03-55'),(4,12,'2017-02-17 09-12-11'),(5,10,'2017-02-17 11-41-17'),(6,18,'2017-02-17 13-05-56'),(7,19,'2017-02-18 08-33-27'),(1,17,'2017-02-19 08-12-31'),(1,1,'2017-02-20 09-50-17'),(3,5,'2017-02-20 09-51-29'),(4,6,'2017-02-20 10-43-39'),(3,1,'2017-02-21 08-32-17'),(1,1,'2017-02-21 10-30-11'),(3,2,'2017-02-21 11-08-45'),(4,3,'2017-02-22 11-46-32'),(2,15,'2017-02-22 13-35-16'),(6,13,'2017-02-23 08-34-48'),(4,24,'2017-02-24 08-32-03'),(2,13,'2017-02-25 08-03-12'),(7,17,'2017-02-25 09-34-23'),(7,23,'2017-02-25 11-32-54'),(5,12,'2017-02-26 11-47-34'),(6,4,'2017-02-27 12-12-34'),(1,1,'2017-02-28 08-59-22'); + + +-- TILL ASSIGNMENT 4 + +select * from customers +where Last_Name in('Taylor','Bluth','Armstrong'); + +select * from customers +where First_Name not in('Katie','John','George'); + +select productID, customerID, Date_Time from orders +where Date_Time between '2017-01-01 00-00-00' and '2017-01-07 23-59-59' ; + +select * from customers +where customerID between 5 and 10; + +select * from customers where Last_Name between 'B' and 'L'; + +select * from customers +where Last_Name like 'W%' ; + +select * from customers +where Last_Name like '%o'; + +select * from customers +where First_Name like '%o%'; + +select * from products +where Price like '3%'; + +select * from products +order by Price asc; + +select * from customers +order by Last_Name asc; + +select * from orders +where customerID=1 order by Date_Time desc; + +select distinct CoffeeOrigin +from products; + +select distinct customerID from orders +where Date_Time between '2017-02-01 00-00-00' and '2017-02-28 23-59-59'; + +select * from customers +where customerID > 5 limit 5; + +select * from customers +order by Last_Name limit 10 ; + +select Name as ProductName, Price, CoffeeOrigin as Country +from products; + +select products.Name, +orders.Date_time +from orders +inner join products on +orders.productID = products.productID; + +select products.Name, +products.Price, +orders.Date_Time +from products inner join orders on +orders.productID = products.productID +where products.Name='Americano' +order by Date_Time desc; + +select customers.First_Name, +customers.ContactNumber +from(( orders inner join customers on +orders.customerID=customers.customerID) +inner join products on orders.productID = products.productID) +where products.Name='Espresso'; + +select orders.orderID, +customers.First_Name, +customers.Last_Name, +customers.ContactNumber, +orders.Date_Time +from orders inner join customers on +orders.customerID = customers.customerID +order by Date_Time desc limit 10; + +update orders set customerID = null where orderID=1; + +select orders.orderID, +customers.First_Name, +customers.Last_Name, +customers.ContactNumber, +orders.Date_Time +from orders left join customers on +orders.customerID = customers.customerID +order by Date_Time desc limit 10; + +select orders.orderID, +customers.First_Name, +customers.Last_Name, +customers.ContactNumber, +orders.Date_Time +from customers left join orders on +orders.customerID = customers.customerID +order by Date_Time desc limit 10; + +select orders.orderID, +customers.First_Name, +customers.Last_Name, +customers.ContactNumber, +orders.Date_Time +from customers right join orders on +orders.customerID = customers.customerID +order by Date_Time desc limit 10; + +select orders.orderID, +customers.Last_Name, +customers.First_Name, + +customers.ContactNumber, +orders.Date_Time +from orders right join customers on +orders.customerID = customers.customerID +order by Date_Time desc limit 10; + +update orders set customerID = 1 where orderID=1; + +select products.Name,products.Price,customers.First_Name, +customers.Last_Name, orders.Date_Time +from(( orders inner join customers on +orders.customerID=customers.customerID) +inner join products on orders.productID = products.productID); + +select products.Name,products.Price,customers.First_Name, +customers.Last_Name, orders.Date_Time +from(( orders inner join customers on +orders.customerID=customers.customerID) +inner join products on orders.productID = products.productID) +where Last_Name ='Martin' +order by Date_Time desc;