Skip to content

Instantly share code, notes, and snippets.

@PierreZ
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierreZ/aaa9b3bd04d5271d596d to your computer and use it in GitHub Desktop.
Save PierreZ/aaa9b3bd04d5271d596d to your computer and use it in GitHub Desktop.
Mysql Request
1) SELECT nom,salaire from employe WHERE salaire > 1000 AND salaire <1500 ORDER BY salaire,nom;
2) SELECT nom,salaire,comm from employe WHERE comm != 'NULL';
3) SELECT nom,date_embauche from employe WHERE (date_embauche BETWEEN '2001-01-01' AND '2001-12-31') ORDER BY date_embauche;
4) SELECT * from employe where fonction!= 'secretaire';
5) SELECT nom from employe WHERE (num_service=20 OR num_service=30) AND fonction='directeur';
6) SELECT * from employe WHERE nom REGEXP '^[lLeE]' ORDER BY LENGTH(nom),nom;
7) select nom,datediff(now(), date_embauche) AS duree from employe order by duree;
8) SELECT nom,fonction,(IF(comm!='NULL',salaire+comm,salaire)) AS revenu from employe ORDER BY revenu;
9) SELECT count(*) as total from employe where comm > 0.25*salaire;
10) select MIN(salaire) as salaire_min, ROUND(AVG(salaire),2) as salaire_avg, MAX(salaire) as salaire_max,(ROUND(MAX(salaire)/MIN(salaire))) as rapport from employe;
1.a) INSERT INTO employe (numemp,nom,fonction,numemp_sup,date_embauche,salaire,num_service) VALUES (936,'LeBouc','directeur',839,CURDATE(),4000,40);
1.b) INSERT INTO employe (numemp,nom,fonction,numemp_sup,date_embauche,num_service) VALUES (937,'superinge','ingenieur',936,CURDATE(),40);
1.c) INSERT INTO employe (numemp,nom,fonction,date_embauche,num_service) VALUES (938,'superdirecteur','directeur',CURDATE(),50); (ne marche pas à cause de la clé étrangère)
2.a) UPDATE employe SET salaire = salaire*1.1;
2.b) UPDATE employe set numemp_sup=999 WHERE nom = 'Dupont'; (ne marche pas)
3.a) UPDATE employe set numemp_sup=902 WHERE nom = 'superinge';
3.a) DELETE FROM employe WHERE num_service=40;
3.b) UPDATE employe set numemp_sup=566 WHERE numemp_sup = 839; (On peut mettre à NULL c'est plus simple)
3.b) DELETE FROM employe WHERE fonction='pdg';
4.a) SHOW CREATE TABLE employe;
alter table employe drop foreign key employe_ibfk_2;
adter table employe add foreign key (numemp_sup) references employe(numemp) on delete cascade;
Partie 1 - Questions de cours (16 points) -1 si faux
Partie 2 - Modélisation (6 points)
Soit create table => MPD et MCD
Soit MCD => MPD et create table
Partie 3 - requête (10 points)
=> jointures simples, group by, update
Partie 4 - SQL2French_vulgarisation (8 points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment