-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheater seating.sql
360 lines (319 loc) · 14.3 KB
/
Theater seating.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
drop schema if exists private cascade;
drop table if exists SeatRow, SeatNum, seat, ticket cascade;
drop table if exists customer cascade;
create schema private;
create table SeatRow(
row Varchar(2) primary key
);
create table SeatNum(
num int primary key
);
create table Seat(
SeatRow Varchar,
SeatNumber int,
Section text not null,
side text not null,
PricingTier text not null,
Wheelchair boolean not null,
constraint pk Primary Key (SeatRow,SeatNumber),
constraint fkrow foreign key(SeatRow)references seatRow (row),
constraint fknum foreign key(SeatNumber)references seatNum (num),
check (side like 'Right' or side like 'Middle' or side like 'Left'),
check (section like 'Balcony' or section like 'Main Floor'),
check (PricingTier like 'Upper Balcony' or PricingTier like 'Side' or PricingTier like 'Orchestra'),
check(Wheelchair = true or Wheelchair = false),
check(SeatRow not like 'I')
);
create table public.Customer(
CustomerID int primary key,
FirstName text,
LastName text
);
create table private.customer(
CustomerID int primary key,
creditCard bigint unique,
constraint CustomerID foreign key(CustomerID) references public.customer(CustomerID)
);
create table Ticket(
TicketNumber serial primary key,
CustomerID int,
SeatRow Varchar,
SeatNumber int,
ShowTime timestamp,
constraint fk1 foreign key (CustomerID) references public.customer(customerID),
constraint fk2 foreign key (SeatRow, SeatNumber) references Seat(SeatRow, SeatNumber),
constraint tik unique(Showtime, SeatRow, SeatNumber)
);
-- SeatRow Varchar,
-- SeatNumber int,
-- Section text not null,
-- side text not null,
-- PricingTier text not null,
-- Wheelchair boolean not null,
-- insert into seat values('a', 102, 'Main Floor', 'Middle', 'Orchestra', false);
insert into seatRow (row) values('A');
insert into seatRow (row) values('B');
insert into seatRow (row) values('C');
insert into seatRow (row) values('D');
insert into seatRow (row) values('E');
insert into seatRow (row) values('F');
insert into seatRow (row) values('G');
insert into seatRow (row) values('H');
insert into seatRow (row) values('J');
insert into seatRow (row) values('K');
insert into seatRow (row) values('L');
insert into seatRow (row) values('M');
insert into seatRow (row) values('N');
insert into seatRow (row) values('O');
insert into seatRow (row) values('P');
insert into seatRow (row) values('Q');
insert into seatRow (row) values('R');
insert into seatRow (row) values('AA');
insert into seatRow (row) values('BB');
insert into seatRow (row) values('CC');
insert into seatRow (row) values('DD');
insert into seatRow (row) values('EE');
insert into seatRow (row) values('FF');
insert into seatRow (row) values('GG');
insert into seatRow (row) values('HH');
insert into seatNum(num) values( generate_series(1,15));
insert into seatNum(num) values( generate_series(100,128));
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'A' or row = 'B' or row = 'C')
and num < 11
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'D' or row = 'E' or row = 'F')
and num < 12
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'G' or row = 'H' or row = 'J')
and num < 13
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'K' or row = 'L' or row = 'M')
and num < 14
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'N' or row = 'O' or row = 'P')
and num < 15
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'Q' or row = 'R' )
and num < 16
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Orchestra', false
from seatRow, seatNum
where (row = 'A' or row = 'B' or row = 'C' or row = 'D' OR ROW = 'E' OR ROW = 'F' OR ROW = 'G' OR ROW = 'H' OR ROW = 'I' OR ROW ='J' OR ROW = 'K' OR ROW = 'L' OR ROW = 'M' OR ROW = 'N' OR ROW = 'O' OR ROW = 'P')
and num >100 and num < 107 and num %2 =1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Orchestra', false
from seatRow, seatNum
where (row = 'A' or row = 'B' or row = 'C' or row = 'D' OR ROW = 'E' OR ROW = 'F' OR ROW = 'G' OR ROW = 'H' OR ROW = 'I' OR ROW ='J' OR ROW = 'K' OR ROW = 'L' OR ROW = 'M' OR ROW = 'N' OR ROW = 'O' OR ROW = 'P')
and num >100 and num < 108 and num %2 =0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where row = 'A'
and num >= 107 and num <=113 and num %2=1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Side', false
from seatRow, seatNum
where row = 'A'
and num >= 107 and num <=114 and num %2=0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Side', false
from seatRow, seatNum
where (row = 'B' or row ='C' OR ROW ='D' OR ROW = 'D')
and num >= 107 and num <=116 and num %2=0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'B' or row ='C' OR ROW ='D' OR ROW = 'D')
and num >= 107 and num <=116 and num %2=1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Side', false
from seatRow, seatNum
where (row = 'F' or row ='G' OR ROW ='H' OR ROW = 'J')
and num >= 107 and num <=118 and num %2=0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'F' or row ='G' OR ROW ='H' OR ROW = 'J')
and num >= 107 and num <=118 and num %2=1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Side', false
from seatRow, seatNum
where (row = 'K' or row ='L' OR ROW ='M' OR ROW = 'N')
and num >= 107 and num <=120 and num %2=0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'K' or row ='L' OR ROW ='M' OR ROW = 'N')
and num >= 107 and num <=120 and num %2=1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Right', 'Side', false
from seatRow, seatNum
where (row = 'O')
and num >= 107 and num <=122 and num %2=0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'O')
and num >= 107 and num <=122 and num %2=1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'P' OR ROW = 'Q' OR ROW = 'R')
and num = 108
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', false
from seatRow, seatNum
where (row = 'P' OR ROW = 'Q' OR ROW = 'R')
and num = 107
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', true
from seatRow, seatNum
where (row = 'P' OR ROW = 'Q' OR ROW = 'R')
and num > 108 AND num <=122 and num %2 =0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Main Floor', 'Left', 'Side', true
from seatRow, seatNum
where (row = 'P' OR ROW = 'Q' OR ROW = 'R')
and num > 108 AND num <=122 and num %2 =1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'AA')
and num >=1 AND num <=13
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Middle', 'Orchestra', false
from seatRow, seatNum
where (row = 'BB' OR ROW = 'CC' OR ROW = 'DD')
and num >=1 AND num <=14
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Middle', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'EE' OR ROW = 'FF')
and num >=1 AND num <=10
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Middle', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'GG' OR ROW = 'HH')
and num >=1 AND num <=11
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Right', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'EE' OR ROW = 'FF')
and num >=102 AND num <=122 and num % 2 =0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Left', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'EE' OR ROW = 'FF')
and num >=102 AND num <=122 and num % 2 =1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Right', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'GG')
and num >=102 AND num <=120 and num % 2 =0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Left', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'GG')
and num >=102 AND num <=120 and num % 2 =1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Right', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'HH')
and num >=102 AND num <=118 and num % 2 =0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Left', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'HH')
and num >=102 AND num <=118 and num % 2 =1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Right', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'AA' OR ROW = 'BB' OR ROW = 'CC')
and num >=102 AND num <=125 AND num %2 = 0
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Left', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'AA' OR ROW = 'BB' OR ROW = 'CC')
and num >=101 AND num <=125 AND num %2 = 1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Left', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'DD' )
and num >=101 AND num <=125 AND num %2 = 1
;
insert into seat(seatRow, seatNumber, section, side, PricingTier, Wheelchair)
select seatRow.row, seatNum.num, 'Balcony', 'Right', 'Upper Balcony', false
from seatRow, seatNum
where (row = 'DD' )
and num >=101 AND num <=126 AND num %2 = 0
;
insert into Customer(CustomerID,FirstName, LastName )
Values(1234, 'Mike', 'Johnson')
;
insert into Private.Customer(CustomerID,creditCard )
Values(1234, 1234567887654321)
;
insert into Ticket(CustomerID, SeatRow,SeatNumber,ShowTime)
Values(1234, 'A', 6, '2017-12-15 14:00:00');
insert into Ticket(CustomerID, SeatRow,SeatNumber,ShowTime)
Values(1234, 'A', 8, '2017-12-15 14:00:00');
insert into Ticket(CustomerID, SeatRow,SeatNumber,ShowTime)
Values(1234, 'A', 10, '2017-12-15 14:00:00');
insert into Ticket(CustomerID, SeatRow,SeatNumber,ShowTime)
Values(1234, 'A', 9, '2017-12-15 14:00:00');
-- select * from seat ORDER by seatNumber;
-- select * from seat ORDER by seatRow;
-- select * from seat;
select Ticket.ticketnumber, ticket.customerid, ticket.seatrow, ticket.seatnumber, ticket.showtime, private.customer.creditcard
from Ticket
join private.customer
on Ticket.customerID = private.Customer.customerID
;
-- select * from seatNum;