-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zad-3.sql
296 lines (211 loc) · 6.52 KB
/
Zad-3.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
create table if not exists genre(
id serial not null,
name varchar(40) not null,
constraint genre_pk primary key (id)
);
create table if not exists artist(
id serial not null,
name varchar(40) not null,
constraint atist_pk primary key (id)
);
create table if not exists genres_artist(
genre_id integer not null,
artist_id integer not null,
constraint genre_artist_fk foreign key(genre_id) references genre(id),
constraint genre_artists_fk1 foreign key (artist_id) references artist(id)
);
create table if not exists album(
id serial not null,
name varchar(40) not null,
year integer not null,
constraint album_pk primary key (id)
);
create table if not exists artist_album(
artist_id integer not null,
album_id integer not null,
constraint artist_album_fk foreign key (album_id) references album(id),
constraint artist_album_fk1 foreign key (artist_id) references artist(id)
);
create table if not exists track(
id serial not null,
name varchar(40) not null,
album_id integer not null,
duration integer second not null,
constraint track_pk primary key (id),
constraint track_fk foreign key (album_id) references album (id)
);
create table if not exists collection(
id serial not null,
name varchar(40) not null,
year integer not null,
constraint collection_pk primary key (id)
);
create table if not exists track_collection(
track_id int not null,
collection_id int not null,
constraint track1_collection_pk primary key (track_id, collection_id),
constraint track1_collection_fk foreign key (collection_id) references collection (id),
constraint track_collection_fk foreign key (track_id) references track (id)
);
insert into genre(id,name)
values (1, 'Classic');
insert into genre(id,name)
values (2, 'Pop');
insert into genre(id,name)
values (3, 'Rock');
insert into genre(id,name)
values (4, 'Rap');
insert into genre(id,name)
values (5, 'RnB');
insert into artist (name)
values ('Rhiana')
insert into artist (name)
values ('Eminem')
insert into artist (name)
values ('Mozart')
insert into artist (name)
values ('Queen')
insert into artist (name)
values ('Linkin Park')
insert into artist (name)
values ('Sia')
insert into artist (name)
values ('Grot')
insert into artist (name)
values ('Usher')
insert into genres_artist (genre_id, artist_id)
values (1,4)
insert into genres_artist (genre_id, artist_id)
values (2,1)
insert into genres_artist (genre_id, artist_id)
values (2,2)
insert into genres_artist (genre_id, artist_id)
values (3,5)
insert into genres_artist (genre_id, artist_id)
values (3,6)
insert into genres_artist (genre_id, artist_id)
values (4,7)
insert into genres_artist (genre_id, artist_id)
values (5,8)
insert into genres_artist (genre_id, artist_id)
values (4,3)
insert into album (name, year)
values ('first', 2018)
insert into album (name, year)
values ('Lose Yourself', 2008)
insert into album (name, year)
values ('My life', 2008)
insert into album (name, year)
values ('My vision', 2020)
insert into album (name, year)
values ('Chocolate', 2019)
insert into album (name, year)
values ('Numb', 2019)
insert into album (name, year)
values ('Best', 2010)
insert into album (name, year)
values ('New', 2011)
insert into album (name, year)
values ('New area', 2022)
insert into artist_album (artist_id, album_id)
values (1,4)
insert into artist_album (artist_id, album_id)
values (2,3)
insert into artist_album (artist_id, album_id)
values (3,5)
insert into artist_album (artist_id, album_id)
values (4,2)
insert into artist_album (artist_id, album_id)
values (5,8)
insert into artist_album (artist_id, album_id)
values (6,1)
insert into artist_album (artist_id, album_id)
values (7,6)
insert into artist_album (artist_id, album_id)
values (8,7)
insert into track (name, album_id, duration)
values ('Life', 2, '00:04:50')
insert into track (name, album_id, duration)
values ('My rules', 3, '00:05:00')
insert into track (name, album_id, duration)
values ('Numb', 6, '00:02:50')
insert into track (name, album_id, duration)
values ('Firt', 8, '00:03:10')
insert into track (name, album_id, duration)
values ('The Best', 1, '00:02:50')
insert into track (name, album_id, duration)
values ('My path', 6, '00:02:40')
insert into track (name, album_id, duration)
values ('My life', 5, '00:03:10')
insert into track (name, album_id, duration)
values ('I think', 7, '00:04:00')
insert into track (name, album_id, duration)
values ('Today', 4, '00:05:15')
insert into track (name, album_id, duration)
values ('My City', 4, '00:02:30')
insert into track (name, album_id, duration)
values ('Bad', 1, '00:04:40')
insert into track (name, album_id, duration)
values ('Roses', 8, '00:03:30')
insert into track (name, album_id, duration)
values ('Money', 5, '00:03:10')
insert into track (name, album_id, duration)
values ('Lose Yourself', 2, '00:02:20')
insert into collection (name, year)
values ('The Best', 2020)
insert into collection (name, year)
values ('Dance', 2018)
insert into collection (name, year)
values ('Disco', 2021)
insert into collection (name, year)
values ('All stars', 2018)
insert into collection (name, year)
values ('Artists', 2020)
insert into collection (name, year)
values ('Cool', 2010)
insert into collection (name, year)
values ('Bands', 2015)
insert into collection (name, year)
values ('Fresh', 2017)
insert into track_collection (track_id, collection_id)
values (3,1)
insert into track_collection (track_id, collection_id)
values (1,2)
insert into track_collection (track_id, collection_id)
values (8,4)
insert into track_collection (track_id, collection_id)
values (2,5)
insert into track_collection (track_id, collection_id)
values (6,3)
insert into track_collection (track_id, collection_id)
values (4,8)
insert into track_collection (track_id, collection_id)
values (10,7)
insert into track_collection (track_id, collection_id)
values (15,6)
insert into track_collection (track_id, collection_id)
values (14,4)
insert into track_collection (track_id, collection_id)
values (9,5)
insert into track_collection (track_id, collection_id)
values (5,1)
insert into track_collection (track_id, collection_id)
values (4,3)
insert into track_collection (track_id, collection_id)
values (13,8)
insert into track_collection (track_id, collection_id)
values (8,3)
insert into track_collection (track_id, collection_id)
values (4,4)
select name, year
from album
select max(duration)
from track
select name, duration from track
where duration >= '00:03:30'
select name from collection
where year between 2018 and 2020
select name from artist
where name not like '% %'
select name from track
where name like '%My%'