This repository was archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassignment-1.sql
330 lines (259 loc) · 5.99 KB
/
assignment-1.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
-- Anindya Kundu - 510817020
-- Create Table cust
create table cust (
Cust_id varchar2(3),
Lname varchar2(15),
Fname varchar2(15),
Area varchar2(2),
Phone_no numeric(8)
);
-- Create Table movie
create table movie (
Mv_no numeric(2),
Title varchar(25),
Type varchar(10),
Star varchar(25),
Price numeric(8,2)
);
-- Create Table invoice
create table invoice (
Inv_no varchar2(3),
Mv_no numeric(2),
Cust_id varchar2(3),
Issue_date date,
Return_date date
);
-- Insert values into cust
insert into cust (
Cust_id,
Lname,
Fname,
Area,
Phone_no
)
values (
'101',
'Verstappen',
'Max',
'RB',
12345678
);
insert into cust (
Cust_id,
Lname,
Fname,
Area,
Phone_no
)
values (
'102',
'Leclerc',
'Charles',
'FR',
23456781
);
insert into cust (
Cust_id,
Lname,
Fname,
Area,
Phone_no
)
values (
'103',
'Ricciardo',
'Daniel',
'RN',
34567812
);
-- Create Table movie
insert into movie (
Mv_no,
Title,
Type,
Star,
Price
)
values (
1,
'Hacksaw Ridge',
'War',
'Andrew Garfield',
130
);
insert into movie (
Mv_no,
Title,
Type,
Star,
Price
)
values (
2,
'Forrest Gump',
'Biography',
'Tom Hanks',
150
);
insert into movie (
Mv_no,
Title,
Type,
Star,
Price
)
values (
3,
'The Dark Knight',
'Action',
'Christian Bale',
180
);
-- Create Table invoice
insert into invoice (
Inv_no,
Mv_no,
Cust_id,
Issue_date,
Return_date
)
values (
'M12',
2,
'102',
'11-JUL-2019',
'13-JUL-2019'
);
insert into invoice (
Inv_no,
Mv_no,
Cust_id,
Issue_date,
Return_date
)
values (
'M13',
3,
'102',
'11-JUL-2019',
'13-JUL-2019'
);
insert into invoice (
Inv_no,
Mv_no,
Cust_id,
Issue_date,
Return_date
)
values (
'M14',
3,
'101',
'14-JUL-2019',
'29-AUG-2019'
);
-- Queries
--1
select Fname, Lname from cust;
--2
select Type from movie;
--3
select * from cust where Phone_no > 5550000;
--4
select * from movie where Type = 'Action' or Type = 'Comedy';
--5
select * from movie where Price > 150 and Price < 200;
--6
select * from cust where Fname like '_a%';
--7
select Lname from cust where Lname like 's%' or Lname like 'f%';
--8
select * from cust where Area like '_a%';
--9
select * from cust where Area = 'da' or Area = 'mu' or Area = 'gh';
--10
select Mv_no, Title, Type from movie where Star like 'm%';
--11
select Title, Price * 15 as New_price from movie where Price > 150;
--12
select * from movie order by Title ASC;
--13
select Title, Type from movie where not Type = 'Horror';
--14
select Price / (Price - 100) as New_price from movie where Title = 'Home Alone';
--15
select Fname, Lname, Area, Cust_id from cust where Phone_no = null;
--16
select Fname, Lname from cust where Lname = null;
--17
select * from invoice where Issue_date like '%-SEP-%';
--18
select count(Cust_id) from cust;
--19
select sum(Price) from movie;
--20
select avg(Price) from movie;
--21
select max(Price) as max_price, min(Price) as min_price from movie;
--22
select count(Title) from movie where Price >= 150;
--23a
select 'The Invoice no. of Customer Id ' || Cust_id || ' is ' || Inv_no || ' and Movie no. is ' || Mv_no || '.' as Customer_Details from invoice;
--23b
select Cust_id || ' has taken Movie no. ' || Mv_no || ' on ' || Issue_date || ' and will return on ' || Return_date as Customer_Details from invoice;
--24
select Type, avg(Price) as Avg_Price from movie group by Type;
--25
select Type, count(Title) as Count from movie group by Type;
--26
select Type, count(Title) as Count from movie group by Type having Type = 'Comedy' or Type = 'Thriller';
--27
select Type, avg(Price) as Avg_Price from movie group by Type having avg(Price) <= 150;
--28
select Type, avg(Price) as Avg_Price from movie where Price >= 150 group by Type having Type = 'Comedy' or Type = 'Thriller';
--29
select Mv_no from invoice, cust where invoice.Cust_id = cust.Cust_id and cust.Fname = 'Ivan';
--30
select Fname, Lname, Mv_no from cust, invoice where invoice.Cust_id = cust.Cust_id;
--31
select Title, Cust_id, invoice.Mv_no from movie, invoice where invoice.Mv_no = movie.Mv_no;
--32
select Title, Type from movie, invoice, cust where cust.fname = 'Daniel' and cust.Cust_id = invoice.Cust_id and invoice.Mv_no = movie.Mv_no;
--33
select Fname, Lname from cust, movie, invoice where cust.Cust_id = invoice.Cust_id and invoice.Mv_no = movie.Mv_no and movie.Type = 'Biography';
--34
select 'The movie taken by ' || Fname || ' ' || Lname || ' is ' || Title || '.' as Movie_Details from cust, movie, invoice where invoice.Cust_id = cust.Cust_id and invoice.Mv_no = movie.Mv_no and movie.Mv_no >= 3;
--35
select Fname, Lname from cust where Cust_id in (select Cust_id from invoice where Mv_no = 1);
--36
select Fname, Lname, Area from cust where Cust_id = (select Cust_id from invoice where Inv_no = 'M14');
--37
select Title from movie where Mv_no in (select Mv_no from invoice where Cust_id in (select Cust_id from cust where Fname = 'Max' or Fname = 'Daniel'));
--38
select Type, Mv_no from movie where Mv_no in (select Mv_no from invoice where Cust_id = '101' or Cust_id = '102');
--39
select Cust_id from cust where Cust_id = (select Cust_id from invoice where Mv_no = (select Mv_no from movie where Star = 'Christian Bale'));
--40
select Fname, Lname, Phone_no from cust where Cust_id in (select Cust_id from invoice where extract(month from Issue_date) < 8);
--41
select Mv_no, Title from movie where Mv_no in (select Mv_no from invoice);
--42
select Inv_no, Issue_date from invoice;
--43
select to_char(Return_date, 'Month') as Return_date from invoice;
--44
select to_char(Issue_date, 'dd-Month-yy') as Issue_dates from invoice;
--45
select sysdate + 15 as New_date from dual;
--46
select floor(sysdate - Return_date) as Elapsed from dual, invoice;
--47
update cust set Phone_no = 56781234 where Fname = 'Lewis';
--48
update invoice set Issue_date = to_date('24/07/93', 'dd/mm/yy') where Cust_id = 101;
--49
delete from invoice where Inv_no = '104';
--50
delete from invoice where Return_date < to_date('10/07/93', 'dd/mm/yy');
--51
update invoice set Return_date = to_date('16-08-93', 'dd-mm-yy') where Inv_no = '104';