-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgreSQL.Local.v17.sql
More file actions
149 lines (125 loc) · 3.49 KB
/
PostgreSQL.Local.v17.sql
File metadata and controls
149 lines (125 loc) · 3.49 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
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
-- Management PostgreSQL.Local.v17.
-- Date: 21-Feb-2025
-- Time: 12:32:12 am
select
table_name
from information_schema.tables
where table_schema='public';
select * from pg_catalog.pg_database as pd ;
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
select
table_name
from information_schema.tables
where table_schema='public';
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-- Terminate all connections to the database
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'dojo.spring'
AND pid <> pg_backend_pid();
-- Chinook Music Store Database.
-- Date: 21-Feb-2025
-- Time: 12:32:12 am
select al.title, ar."name" from album as al inner join artist as ar on ar.artist_id = al.artist_id
order by al.title ASC;
SELECT to_char(i.invoice_date, 'YYYY') AS "year",
c.first_name || ' ' || c.last_name AS "customer",
c.city AS "city",
i.total AS amount,
STRING_AGG(DISTINCT ar.name, ', ') AS "artists",
e.first_name || ' ' || e.last_name AS "employee"
FROM Invoice AS i
INNER JOIN customer AS c ON c.customer_id = i.customer_id
INNER JOIN employee AS e ON e.employee_id = c.support_rep_id
INNER JOIN invoice_line AS il ON il.invoice_id = i.invoice_id
INNER JOIN track as tr ON tr.track_id = il.track_id
INNER JOIN album as al ON al.album_id = tr.album_id
INNER JOIN artist as ar ON ar.artist_id = al.artist_id
GROUP BY Year,
customer,
c.City,
amount,
employee
ORDER BY Year ASC,
amount DESC
LIMIT 10 OFFSET 0;
-- Spring Boot Backup Database.
-- Date: 21-Feb-2025
-- Time: 12:32:12 am
Drop the database
drop database "dojo.spring" with force;
create new database "dojo.spring" with owner 'postgres';
-- Airlines Database.
-- Date: 21-Feb-2025
-- Time: 12:32:12 am
select
airport_code,
airport_name,
city,
coordinates,
timezone
from
airports_data;
SELECT ac.aircraft_code as "code",
json_extract(ac.model, '$.en') as "model",
ac.range as "range"
FROM aircrafts_data ac
ORDER BY range DESC;
CREATE VIEW IF NOT EXISTS aircrafts AS
SELECT ac.aircraft_code as [code],
json_extract(ac.model, '$.en') as [model],
ac.range as [range]
FROM aircrafts_data ac
ORDER BY range DESC;
SELECT
ap.airport_code as [code],
json_extract(ap.airport_name, '$.en') as [name],
json_extract(ap.city, '$.en') as [city],
ap.coordinates as [coordinates],
ap.timezone as [timezone]
FROM airports_data ap
ORDER BY city DESC;
CREATE VIEW IF NOT EXISTS airports AS
SELECT
ap.airport_code as [code],
json_extract(ap.airport_name, '$.en') as [name],
json_extract(ap.city, '$.en') as [city],
ap.coordinates as [coordinates],
ap.timezone as [timezone]
FROM airports_data ap
ORDER BY city DESC;
-- F1 DB.
-- Date: 21-Feb-2025
-- Time: 12:32:12 am
select
id,
"name",
first_name,
last_name,
full_name,
abbreviation,
permanent_number,
gender,
date_of_birth,
date_of_death,
place_of_birth,
country_of_birth_country_id,
nationality_country_id,
second_nationality_country_id,
best_championship_position,
best_starting_grid_position,
best_race_result,
total_championship_wins,
total_race_entries,
total_race_starts,
total_race_wins,
total_race_laps,
total_podiums,
total_points,
total_championship_points,
total_pole_positions,
total_fastest_laps,
total_driver_of_the_day,
total_grand_slams
from
driver;