Commit d6595165 authored by Dimitri Nicolas's avatar Dimitri Nicolas
Browse files

Merge

parents 78a62055 a1436a19
......@@ -161,84 +161,6 @@ CREATE TABLE IF NOT EXISTS ExemplairePret (
FOREIGN KEY (pret) REFERENCES Pret(pretID),
PRIMARY KEY (ref, pret)
);
/*--------------------------------- VIEWS -----------------------------------------------*/
CREATE VIEW Exemplaires_Disponibles AS
SELECT DISTINCT(codeunique), titre, editeur, genre
FROM ressource
JOIN exemplaire ON exemplaire.ressource = ressource.codeunique
WHERE disponible = TRUE;
CREATE VIEW Repartition_Emprunts AS
SELECT
CASE
WHEN exemplaire.ressource IN (SELECT codeunique FROM livre) THEN 'livre'
WHEN exemplaire.ressource IN (SELECT codeunique FROM film) THEN 'film'
WHEN exemplaire.ressource IN (SELECT codeunique FROM oeuvremusicale) THEN 'oeuvre musicale'
END AS "category", COUNT(exemplaire.ressource) AS "nb_ressources", (COUNT(exemplaire.ressource)/SUM(COUNT(exemplaire.ressource)) OVER()) * 100 AS "part"
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 ****** */
CREATE OR REPLACE FUNCTION check_exclusivite_realisateur()
......
CREATE VIEW Exemplaires_Disponibles AS
SELECT DISTINCT(codeunique), titre, editeur, genre
FROM ressource
JOIN exemplaire ON exemplaire.ressource = ressource.codeunique
WHERE disponible = TRUE;
CREATE VIEW Repartition_Emprunts AS
SELECT
CASE
WHEN exemplaire.ressource IN (SELECT codeunique FROM livre) THEN 'livre'
WHEN exemplaire.ressource IN (SELECT codeunique FROM film) THEN 'film'
WHEN exemplaire.ressource IN (SELECT codeunique FROM oeuvremusicale) THEN 'oeuvre musicale'
END AS "category", COUNT(exemplaire.ressource) AS "nb_ressources", (COUNT(exemplaire.ressource)/SUM(COUNT(exemplaire.ressource)) OVER()) * 100 AS "part"
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;
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