0% found this document useful (0 votes)
19 views2 pages

Corr

The document contains SQL statements that create tables for clients, representatives, and apartments with foreign keys, inserts sample data, and runs queries on the tables including selecting, filtering, aggregating, joining, and ordering data.

Uploaded by

rgererg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Corr

The document contains SQL statements that create tables for clients, representatives, and apartments with foreign keys, inserts sample data, and runs queries on the tables including selecting, filtering, aggregating, joining, and ordering data.

Uploaded by

rgererg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE Client(

codeclt VARCHAR(20) PRIMARY KEY,


nomclt VARCHAR(20),
prenomclt VARCHAR(20),
villeclt VARCHAR(20)
);

CREATE TABLE Representant(


coderep VARCHAR(20) PRIMARY KEY,
nomrep VARCHAR(20),
prenomrep VARCHAR(20)
);

CREATE TABLE Appartement(


ref VARCHAR(20) PRIMARY KEY,
superfcie int,
prix int,
coderep VARCHAR(20),
codeclt VARCHAR(20)
);

ALTER TABLE Appartement ADD CONSTRAINT c1 FOREIGN KEY (coderep) REFERENCES


Representant(coderep);
ALTER TABLE Appartement ADD CONSTRAINT c2 FOREIGN KEY (codeclt) REFERENCES
Client(codeclt);

INSERT INTO Client VALUES ('C1','jerbi','Ali','Tunis');


INSERT INTO Client VALUES ('C2','ayadi','Sami','Sfax');
INSERT INTO Client VALUES ('C3','zayedi','Hela','Sousse');

INSERT INTO Representant VALUES ('R1','Tounsi','Ala');


INSERT INTO Representant VALUES ('R2','Sfaxi','Hedi');
INSERT INTO Representant VALUES ('R3','Gabsi','Amine');

INSERT INTO Appartement VALUES ('A1',500,100,'R2','C1');


INSERT INTO Appartement VALUES ('A2',700,50,'R1','C2');
INSERT INTO Appartement VALUES ('A3',900,150,'R2','C3');

SELECT * FROM Representant;

SELECT DISTINCT villeclt FROM Client;

SELECT COUNT(codeclt) FROM Client;

SELECT * FROM Client


WHERE codeclt = 'C2';

SELECT MAX (prix) FROM Appartement;

SELECT MIN(prix) FROM Appartement;

SELECT nomclt FROM Client


ORDER BY prenomclt ASC;

SELECT ref FROM Appartement a,Client c,Representant r


WHERE a.codeclt = c.codeclt
AND a.coderep = r.coderep
AND villeclt = 'France'
AND nomrep = 'Hedi'
AND prenomrep = 'Sfaxi';

SELECT AVG(prix) from Appartement


ORDER BY superficie;

SELECT COUNT(*) FROM Appartement


WHERE superfcie > 700;

You might also like