· 4 years ago · Feb 28, 2021, 10:10 PM
1CREATE TABLE IF NOT EXISTS clienti
2(
3 customer_id serial primary key,
4 cognome varchar(30) not null,
5 nome varchar(30) not null
6);
7CREATE TABLE IF NOT EXISTS pagamenti
8(
9 payment_id serial primary key,
10 customer_id numeric not null,
11 importo float not null
12);
13
14insert into clienti(cognome, nome)
15values ('Rossi', 'Mario'),
16 ('Verdi', 'Giacomo'),
17 ('Bianchi', 'Alex');
18insert into pagamenti(customer_id, importo)
19values (1, 10.95),
20 (1, 15.95),
21 (1, 20.95),
22 (2, 5.95),
23 (2, 15.95),
24 (2, 35.95);
25
26SELECT a.*, MAX(b.importo) as Max_Importo
27from clienti as a
28 inner join pagamenti as b on a.customer_id = b.customer_id
29group by a.customer_id
30ORDER by customer_id;
31
32
33
34