Skip to content

Commit 7a67b74

Browse files
authored
Add files via upload
1 parent bff51a3 commit 7a67b74

3 files changed

+61
-0
lines changed

Mission 3 Grouping Data.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
create database luckyshrub_db;
2+
3+
use luckyshrub_db;
4+
5+
create table Orders(OrderID int, Department varchar(100), OrderDate date, OrderQty int, OrderTotal int,
6+
primary key (OrderID));
7+
8+
insert into Orders values (1,'Lawn Care','2022-05-05',12,500),(2,'Decking','2022-05-22',150,1450),
9+
(3,'Compost and Stones','2022-05-27',20,780),(4,'Trees and Shrubs','2022-06-01',15,400),
10+
(5,'Garden Decor','2022-06-10',2,1250),(6,'Lawn Care','2022-06-10',12,500),(7,'Decking','2022-06-25',150,1450),
11+
(8,'Compost and Stones','2022-05-29',20,780),(9,'Trees and Shrubs','2022-06-10',15,400),
12+
(10,'Garden Decor','2022-06-10',2,1250),(11,'Lawn Care','2022-06-25',10,400),
13+
(12,'Decking','2022-06-25',100,1400),(13,'Compost and Stones','2022-05-30',15,700),
14+
(14,'Trees and Shrubs','2022-06-15',10,300),(15,'Garden Decor','2022-06-11',2,1250),
15+
(16,'Lawn Care','2022-06-10',12,500),(17,'Decking','2022-06-25',150,1450),(18,'Trees and Shrubs','2022-06-10',15,400),
16+
(19,'Lawn Care','2022-06-10',12,500),(20,'Decking','2022-06-25',150,1450),(21,'Decking','2022-06-25',150,1450);
17+
18+
-- Task 1: group all records that have the same order date.
19+
select OrderDate from Orders group by OrderDate;
20+
21+
-- Task 2: retrieve the number of orders placed on the same day.
22+
select OrderDate, COUNT(OrderID) from Orders group by OrderDate;
23+
24+
-- Task 3: retrieve the total order quantities placed by each department.
25+
select Department, sum(OrderQty) from Orders group by Department;
26+
27+
-- Task 4: retrieve the number of orders placed on the same day between the following dates:
28+
-- 1st June 2022 and 30th June 2022.
29+
select OrderDate,COUNT(OrderID) from Orders group by OrderDate
30+
having OrderDate between '2022-06-01' and '2022-06-30';

Mission 4 MySQL REPLACE statement.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create database Lucky_Shruby;
2+
use Lucky_shruby;
3+
create table Orders (OrderID int not null primary key, ClientID varchar(10), ProductID varchar(10), Quantity int,
4+
Cost decimal(6,2));
5+
6+
insert into Orders (OrderID, ClientID, ProductID, Quantity, Cost) values (1, "Cl1", "P1", 10, 500),
7+
(2, "Cl2", "P2", 5, 100), (3, "Cl3", "P3", 20, 800), (4, "Cl4", "P4", 15, 150), (5, "Cl3", "P3", 10, 450),
8+
(6, "Cl2", "P2", 5, 800), (7, "Cl1", "P4", 22, 1200), (8, "Cl1", "P1", 15, 150);
9+
10+
-- Task 1: Write a SQL REPLACE statement that inserts two new orders
11+
replace into Orders (OrderID, ClientID, ProductID, Quantity, Cost) values (9, "Cl1", "P1", 10, 5000),
12+
(10, "Cl2", "P2", 5, 100);
13+
14+
-- Task 2: change a record
15+
replace into Orders set OrderID = 9, ClientID = "Cl1", ProductID = "P1", Quantity = 10, Cost = 500;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
create database Mangata_Gallo;
2+
use Mangata_Gallo;
3+
4+
-- Task 1: Create the Clients table with the required constraints
5+
create table Clients (ClientID int primary key, FullName varchar(100) not null, PhoneNumber int not null unique);
6+
show columns from Clients;
7+
8+
-- Task 2: Create the Items table with the required constraints:
9+
create table Items (ItemID int primary key, ItemName varchar(100) not null, Price decimal(5,2) not null);
10+
show columns from Items;
11+
12+
-- Task 3: Create the Orders table with the required constraints
13+
create table Orders ( OrderID int primary key, ItemID int not null,ClientID int not null,
14+
Quantity int not null check (Quantity < 4),Cost decimal(6,2) not null, foreign key (ClientID) references Clients (ClientID),
15+
foreign key (ItemID) references Items (ItemID));
16+
show columns from Orders;

0 commit comments

Comments
 (0)