From 7977e5f60ca1b21828a70aa6f1578be2266e6a48 Mon Sep 17 00:00:00 2001
From: Joel Cavat <jcavat@gmail.com>
Date: Fri, 29 Apr 2022 08:28:01 +0200
Subject: [PATCH] Ten first queries

---
 corrections/chapitre_05/conf.sql | 90 ++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 corrections/chapitre_05/conf.sql

diff --git a/corrections/chapitre_05/conf.sql b/corrections/chapitre_05/conf.sql
new file mode 100644
index 0000000..66c3353
--- /dev/null
+++ b/corrections/chapitre_05/conf.sql
@@ -0,0 +1,90 @@
+-- 1
+SELECT V.login, firstname, lastname, loyalty_points
+FROM Visitor as V
+INNER JOIN Fidelity as F ON V.login = F.login
+WHERE loyalty_points < 50;
+
+-- 2
+SELECT V.login, firstname, lastname, loyalty_points
+FROM Visitor as V
+LEFT JOIN Fidelity as F ON V.login = F.login
+WHERE IFNULL(loyalty_points,0) < 50 AND V.login LIKE "l%";
+
+SELECT V.login, firstname, lastname, loyalty_points
+FROM Visitor as V
+LEFT JOIN Fidelity as F ON V.login = F.login
+WHERE (loyalty_points < 50 OR loyalty_points IS NULL) AND V.login GLOB "l*";
+
+-- 3
+SELECT firstname, lastname, loyalty_points
+FROM Visitor as V
+INNER JOIN Fidelity as F ON V.login = F.login;
+
+-- 4
+SELECT * 
+FROM Conference
+WHERE title IN ("databases", "microservices");
+
+SELECT * 
+FROM Conference
+WHERE title <> "databases" OR title IS "microservices";
+
+-- 5
+SELECT title
+FROM Topic;
+
+-- 6
+SELECT DISTINCT title
+FROM Conference;
+
+-- 7
+-- non standard, sqlite only
+SELECT *
+FROM Visitor 
+INTERSECT
+SELECT *
+FROM Speaker;
+
+-- standard
+SELECT *
+FROM Visitor 
+INNER JOIN Speaker ON Visitor.login = Speaker.login;
+
+-- sous-requête IN
+SELECT *
+FROM Visitor
+WHERE login IN (
+    SELECT login FROM Speaker
+);
+
+-- sous-requête EXISTS
+SELECT *
+FROM Visitor
+WHERE EXISTS  (
+    SELECT login FROM Speaker
+    WHERE Speaker.login = Visitor.login
+);
+
+
+-- 8
+SELECT *
+FROM Speaker
+WHERE login NOT IN (
+    SELECT login FROM Visitor
+);
+
+-- 9
+SELECT Topic.title, COUNT(id_conference)
+FROM Topic
+LEFT JOIN Conference ON Conference.title = Topic.title
+GROUP BY Topic.title;
+
+-- 10
+SELECT *
+FROM Visitor 
+WHERE login NOT IN (SELECT login FROM Registration);
+
+SELECT *
+FROM Visitor 
+LEFT JOIN Registration ON Visitor.login = Registration.login
+WHERE id_conference IS NULL;
-- 
GitLab