-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChapter_15.sql
144 lines (142 loc) · 4.02 KB
/
Chapter_15.sql
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @Author: ADITYA KUMAR SINGH <the__martian>
* @Email: [email protected]
* @Filename: Chapter_15.sql
*/
-----------------------------------------------------------------
I N T E R N A L P R O B L E M S
-----------------------------------------------------------------
/*
“Change products by increasing the retail price by 10 percent.”
*/
update
Products
set
price = price + (price + 0.1 * price);
-----------------------------------------------------------------
/*
“Modify products by increasing the retail price by 4 percent for
products that are clothing (category 3).”
*/
update
Products
set
RetailPrice = RetailPrice * 1.04
where
CategoryID = 3;
-----------------------------------------------------------------
/*
“Modify classes by changing the classroom to 1635 and the
schedule dates from Monday-Wednesday-Friday to Tuesday-Thursday-
Saturday for all drawing classes (subject ID 13).”
*/
UPDATE
Classes
SET
ClassRoomID = 1635,
MondaySchedule = 0,
WednesdaySchedule = 0,
FridaySchedule = 0,
TuesdaySchedule = 1,
ThursdaySchedule = 1,
SaturdaySchedule = 1
WHERE
SubjectID = 13;
-----------------------------------------------------------------
/*
“Modify products by increasing the retail price by 4 percent for
products that are clothing.”
*/
UPDATE
Products
SET
RetailPrice = RetailPrice * 1.04
WHERE
CategoryID =
(
SELECT
CategoryID
FROM
Categories
WHERE
CategoryDescription = 'Clothing'
);
-----------------------------------------------------------------
/*“Modify classes by changing the classroom to 1635 and the
schedule dates from Monday-Wednesday-Friday to Tuesday-Thursday-
Saturday for all drawing classes.”
*/
update
Classes
set
ClassRoomID = 1635,
MondaySchedule = 0,
WednesdaySchedule = 0,
FridaySchedule = 0,
TuesdaySchedule = 1,
ThursdaySchedule =1,
SaturdaySchedule = 1
where
SubjectID in (
select
SubjectID
from
Subjects
where
SubjectName = 'Drawing'
);
-----------------------------------------------------------------
/*
“Change the classes table by setting the start time to 2:00 PM
for all classes taught by Kathryn Patterson.”
*/
update
Classes
set
StartTime = '14:00:00'
where
ClassID in (
select
ClassID
from
Staff S
inner join
Faculty_Classes FC
on FC.StaffID = S.StaffID
where
S.StfFirstName = 'Kathryn'
and
S.StfLastname = 'Patterson'
);
-----------------------------------------------------------------
/*
“Change the orders table by setting the order total to the sum
of quantity ordered times quoted price for all related order
detail rows.”
*/
update
Orders
set
OrderToal = (
select
sum(OD.QuantityOrdered * OD.QuotedPrice)
from
Order_Details OD
where
OD.OrderNumber = Orders.OrderNumber
);
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------