-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-week-challenge.sql
More file actions
61 lines (43 loc) · 1.74 KB
/
sql-week-challenge.sql
File metadata and controls
61 lines (43 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
create table Products(
ID int not null Primary key identity,
ProdName nvarchar(40) not null,
Price decimal not null,
)
create table Orders(
ID int not null Primary Key identity,
ProductId int not null foreign key references Products(ID) on update cascade on delete cascade,
CustomerId int unique,
)
create table Customers(
CustomerRefID int Primary key identity,
ID int foreign Key references Orders(CustomerId) on update cascade on delete cascade,
FirstName nvarchar(30) not null,
LastName nvarchar(30) not null,
CardNumber nvarchar (16) not null,
)
insert into Products values ('lamp', 30.00);
insert into Products values ('tissues', 5.50);
insert into Products values ('orange', 7.50);
insert into Orders values ( 2, 1)
insert into Orders values ( 1, 2)
insert into Orders values ( 3, 3)
insert into Customers values (1 ,'Jack', 'Pflug', 123424235)
insert into Customers values (2 ,'John', 'Smith', 123254235)
insert into Customers values (3 ,'Judy', 'Smith', 123456235)
select * from Products;
select * from Orders;
Select * from Customers;
--inserting iphone
insert into Products values('IPhone', 200);
--adding tina
--insert into Customers values ( null,'Tina', 'Smith', 97520973);
--add Iphone order
insert into Orders values (4, 4);
insert into Customers values (4, 'Tina', 'Smith', 98135490);
-- get all of tinas orders
Select Customers.FirstName from Orders inner join Customers on Orders.CustomerId = Customers.CustomerId where CustomerId = 4;
--revenue generated by iphone
With totalrevenue as(Select Price
-- had I not ran out of time I would've used the CTE to create a variable that store the product price of the iphone and then ran a query to see the sum of the revenue generated
--by orders where the product id =4
b