-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite.sql
More file actions
60 lines (46 loc) · 1.68 KB
/
SQLite.sql
File metadata and controls
60 lines (46 loc) · 1.68 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
CREATE TABLE clients(
NIF text PRIMARY KEY,
nom text,
ciutat text,
edat integer
);
INSERT INTO clients(NIF, nom, ciutat, edat) VALUES ("124A","UAB","Bellaterra",50);
INSERT INTO clients(NIF, nom, ciutat, edat) VALUES ("743V","RENFE","Cerdanyola",100);
----------------------------------------------------
SELECT *
FROM clients
WHERE ciutat="Bellaterra" AND edat>=50
-- WHERE ciutat="Bellaterra" OR ciutat="Cerdanyola"
----------------------------------------------------
SELECT COUNT(*) as num_clinets FROM clients
WHERE ciutat="Bellaterra"
----------------------------------------------------
SELECT ciutat,avg(edat) AS mitja_edat, COUNT(*) as num_clinets FROM clients
WHERE edat > 30
GROUP BY ciutat
HAVING num_clinets>=2
ORDER by mitja_edat ASC
----------------------------------------------------
CREATE TABLE IF not EXISTS vendes (
id integer PRIMARY KEY AUTOINCREMENT,
clients text,
producte text,
data text
);
INSERT INTO vendes(clients,producte,data) VALUES ("123A","1", "2022-11-22");
INSERT INTO vendes(clients,producte,data) VALUES ("743V","2", "2022-11-22");
INSERT INTO vendes(clients,producte,data) VALUES ("145S","1", "2022-11-21");
INSERT INTO vendes(clients,producte,data) VALUES ("741P","2", "2022-11-20");
SELECT data,clients.nom,productes.nom from vendes, productes
WHERE producte=ean AND vendes.clients = clients.nif
order by data
----------------------------------------------------
SELECT * from vendes;
--- to change the value of row
UPDATE vendes set data="2022-11-01" WHERE id=2;
SELECT * from vendes
----------------------------------------------------
SELECT * from clients;
--- to change the value of row
DELETE FROM clients WHERE nif="743V";
SELECT * from clients