Commit af83ea8d authored by Marine Marsal's avatar Marine Marsal
Browse files

Update CREATE.sql

parent 2c0c039c
......@@ -179,6 +179,65 @@ FROM exemplaire
JOIN exemplairepret ON exemplaire.ref = exemplairepret.ref
GROUP BY "category";
CREATE OR REPLACE VIEW RessourcesPopulaires AS
SELECT r.titre, COUNT(ep.ref) nb_emprunt
FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref
GROUP BY r.titre
HAVING COUNT(ep.ref) > 2
ORDER BY COUNT(ep.ref) DESC;
CREATE OR REPLACE VIEW GenresPopulaires AS
SELECT r.genre, COUNT(ep.ref) nb_emprunt
FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref
GROUP BY r.genre
HAVING COUNT(ep.ref) > 2
ORDER BY COUNT(ep.ref) DESC;
CREATE OR REPLACE VIEW LivresPopulaire AS
SELECT r.titre, COUNT(ep.ref) nb_emprunt
FROM Livre l JOIN Ressource r ON l.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref
GROUP BY r.titre
HAVING COUNT(ep.ref) > 2
ORDER BY COUNT(ep.ref) DESC;
CREATE OR REPLACE VIEW OeuvresMusicalesPopulaire AS
SELECT r.titre, COUNT(ep.ref) nb_emprunt
FROM OeuvreMusicale om JOIN Ressource r ON om.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref
GROUP BY r.titre
HAVING COUNT(ep.ref) > 2
ORDER BY COUNT(ep.ref) DESC;
CREATE OR REPLACE VIEW FilmsPopulaires AS
SELECT r.titre, COUNT(ep.ref) nb_emprunt
FROM Film f JOIN Ressource r ON f.codeUnique = r.codeUnique JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref
GROUP BY r.titre
HAVING COUNT(ep.ref) > 2
ORDER BY COUNT(ep.ref) DESC;
CREATE OR REPLACE VIEW DureeMaxEmpruntParAdherent AS
SELECT u.nom, MAX(duree) dureeEmpruntMax
FROM Adherent a JOIN Pret p ON p.adherent = a.login JOIN Utilisateur u ON u.login = a.login
GROUP BY u.nom
ORDER BY MAX(duree) DESC;
CREATE OR REPLACE VIEW DureeMoyenneEmpruntParAdherent AS
SELECT u.nom, AVG(duree) dureeMoyenneEmprunt
FROM Adherent a JOIN Pret p ON p.adherent = a.login JOIN Utilisateur u ON u.login = a.login
GROUP BY u.nom
ORDER BY AVG(duree) DESC;
CREATE OR REPLACE VIEW DureeMaxEmpruntParRessource AS
SELECT r.titre, MAX(duree) dureeEmpruntMax
FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref JOIN Pret p ON p.pretID = ep.pret
GROUP BY r.titre
ORDER BY MAX(duree) DESC;
CREATE OR REPLACE VIEW DureeMoyenneEmpruntParRessource AS
SELECT r.titre, AVG(duree) dureeMoyenneEmprunt
FROM Ressource r JOIN Exemplaire e ON e.ressource = r.codeUnique JOIN ExemplairePret ep ON ep.ref = e.ref JOIN Pret p ON p.pretID = ep.pret
GROUP BY r.titre
ORDER BY AVG(duree) DESC;
/* ****** TRIGGERS ****** */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment