Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

*Michel Dieng*

*LICENCE2*
*ESTI*

Exercice2:
Microsoft Windows [version 10.0.19043.1826]
(c) Microsoft Corporation. Tous droits réservés.

C:\Users\User>mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.4.24-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create user 'exercice2'@'localhost' identified by 'pass';


Query OK, 0 rows affected (0.032 sec)

MariaDB [(none)]> grant all on *.* to 'exercice2'@'localhost';


Query OK, 0 rows affected (0.054 sec)

MariaDB [(none)]> exit


Bye

C:\Users\User>mysql -h localhost -u exercice2 -p


Enter password: ****
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.4.24-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database entreprises;


Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use entreprises;


Database changed

Exercice1:
MariaDB [entreprises]> create table departements
-> (
-> DNO int not null primary key,
-> DNOM varchar(50),
-> DIR varchar(50),
-> ville varchar(50));
Query OK, 0 rows affected (0.395 sec)

MariaDB [entreprises]> create table employers


-> (
-> ENO int not null,
-> ENOM varchar(50),
-> PROF varchar(50),
-> DATEDEMB date,
-> SAL int,
-> COMM int,
-> DNO int not null,
-> foreign key(DNO) references departements(DNO));
Query OK, 0 rows affected (0.473 sec)

MariaDB [entreprises]> show tables;


+-----------------------+
| Tables_in_entreprises |
+-----------------------+
| departements |
| employers |
+-----------------------+
2 rows in set (0.001 sec)

MariaDB [entreprises]> desc departements;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| DNO | int(11) | NO | PRI | NULL | |
| DNOM | varchar(50) | YES | | NULL | |
| DIR | varchar(50) | YES | | NULL | |
| ville | varchar(50) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.007 sec)

MariaDB [entreprises]> desc employers;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| ENO | int(11) | NO | | NULL | |
| ENOM | varchar(50) | YES | | NULL | |
| PROF | varchar(50) | YES | | NULL | |
| DATEDEMB | date | YES | | NULL | |
| SAL | int(11) | YES | | NULL | |
| COMM | int(11) | YES | | NULL | |
| DNO | int(11) | NO | MUL | NULL | |
+----------+-------------+------+-----+---------+-------+
7 rows in set (0.007 sec)

1.Donnons la liste des employers ayant une commission


MariaDB [entreprises]> select * from employers where COMM is not null;

2.Donnons les noms,emplois et salaires des employers par emploi croissant,et pour
chaque emploi par salaire decroissant
select ENOM,PROF,SAL from employers order by PROF asc;

3.Donnons le salaire moyen des employers


MariaDB [entreprises]> select avg(SAL) from employers;

4.Donnons le salaire moyen du departement Production


MariaDB [entreprises]> select avg(SAL) from employers,departements where
employers.DNO=departements.DNO and departements.DNO='Production';

5.Donnons le numero de departemnt et leur salaire maximum


MariaDB [entreprises]> select DNO,SAL from departements,employers where
employers.DNO=departements.DNO and employers.SAL=max(SAL) group by DNOM;

6.Donnons les differentes professions et leur salaire moyen.


MariaDB [entreprises]> select PROF,avg(SAL) from employers group by PROF ;

7.Donnons le ou les emplois ayant le salaire moyen le plus bas,ainsi que ce salaire
moyen
MariaDB [entreprises]> select PROF,avg(SAL) from employers where SAL=avg(SAL) group
by PROF;

Exercice2:

Microsoft Windows [version 10.0.19043.1826]


(c) Microsoft Corporation. Tous droits réservés.

C:\Users\User>mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.4.24-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create user 'exercice1'@'localhost' identified by 'pass';


Query OK, 0 rows affected (0.033 sec)

MariaDB [(none)]> grant all on *.* to 'exercice1'@'localhost';


Query OK, 0 rows affected (0.050 sec)

MariaDB [(none)]> exit


Bye

C:\Users\User>mysql -h localhost -u exercice1 -p


Enter password: ****
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 10.4.24-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database tour;


Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use tour;


Database changed
MariaDB [tour]> create table equipe
-> (
-> code_equipe int not null primary key,
-> nom_equipe varchar(50),
-> directeur_sportif varchar(50));
Query OK, 0 rows affected (0.274 sec)

MariaDB [tour]> create table pays


-> (
-> code_pays int not null primary key,
-> nom_pays varchar(50));
Query OK, 0 rows affected (0.216 sec)

MariaDB [tour]> create table coureur


-> (
-> numero_coureur int not null primary key,
-> nom_coureur varchar(50),
-> code_equipe int,
-> code_pays int,
-> foreign key code_equipe references equipe(code_equipe),
-> foreign key code_pays references pays(code_pays));
Query OK, 0 rows affected (0.216 sec)

MariaDB [tour]> create table type_etape


-> (
-> code_type int not null primary key,
-> libelle_type varchar(50));
Query OK, 0 rows affected (0.203 sec)

MariaDB [tour]> create table etape


-> (
-> numero_etape int not null primary key,
-> date_etape date,
-> villedep varchar(50),
-> villearr varchar(50),
-> nbkm int,
-> code_type varchar(50)
-> foreign key code_type references type_etape(code_type));
Query OK, 0 rows affected (0.216 sec)

MariaDB [tour]> create table participer


-> (
-> numero_coureur int,
-> numero_etape int,
-> temps_realise int,
-> foreign key numero_coureur references coureur(numero_coureur),
-> foreign key numero_etape references etape(numero_etape));
Query OK, 0 rows affected (0.203 sec)

MariaDB [tour]> create table attribuer_bonification


-> (
-> numero_etape int,
-> numero_coureur int,
-> km int,
-> rang int,
-> nbsecondes,
-> foreign key numero_etape references etape(numero_etape),
-> foreign key numero coureur references partciper(numero_coureur));
Query OK, 0 rows affected (0.216 sec)

1.
MariaDB [tour]> select numero_coureur,nom_coureur,pays_coureur from
coureur,equipe,pays where equipe.code_equipe=coureur.code_equipe and
pays.code_pays=coureur.code_pays and nom_equipe='Festina';

2.
MariaDB [tour]> select sum(nbkm) from etape;
3.
MariaDB [tour]> select sum(nbkm) from etape,type_etape where
type_etape.code_type=etape.code_type and libelle_type='Haute Montagne' ;

4.
MariaDB [tour]> select nom_coureur from coureur,attribuer_bonification where
coureur.numero_coureur=attribuer_bonification.numero_coureur and km is not null and
rang is not null and nb_seccondes is not null;

5.
MariaDB [tour]> select nom_coureur from coureur,participer where
coureur.numero_coureur=participer.numero_coureur and temps realiser is not null;

You might also like