From 480ae0e86a9721a6f413fcd956de255e91e009f4 Mon Sep 17 00:00:00 2001 From: Juliette Goardon Date: Wed, 29 Nov 2023 22:18:35 +0100 Subject: [PATCH] Done --- .DS_Store | Bin 0 -> 6148 bytes your-code/solutions.sql | 112 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .DS_Store create mode 100644 your-code/solutions.sql diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f68e748bb9878a10e59bc14a1f482859de76d04c GIT binary patch literal 6148 zcmeHKyG{c!5S)bw1<|CW^bb(*2d5}}0Y3obB7_ul5>X1etN1QHjoAl9IA|i#M6=R* z?DdW|7FYn7(;e~Q!_<7=ePU-7akMyNgI&K{Z=Z%?JIVe%;M@zm;1!Q} z#t;4_-Z5a0H{4*&S&z;4@w`ta1*Cu!kOERb3LK$8)zJCX5nNHEfD|}w1^oNa=#E|C zm>8c94$%S-XAFmN9=!yyd4Sjzj){!WEUCn#TD2IKbjDldb%kSM(qVBk ZOIuwiB z8E=se>k>6e0V!~(za(Wzl literal 0 HcmV?d00001 diff --git a/your-code/solutions.sql b/your-code/solutions.sql new file mode 100644 index 0000000..a43c996 --- /dev/null +++ b/your-code/solutions.sql @@ -0,0 +1,112 @@ +USE Publications; + +/* CHALLENGE 1*/ + +SELECT * FROM authors; +SELECT * FROM Publications.titleauthor; +SELECT * FROM Publications.titles; +SELECT * FROM Publications.publishers; + + +/* ADDING ONLY THE TITLE ID*/ +SELECT + authors.au_id, + authors.au_lname, + authors.au_fname, + titleauthor.au_id, + titleauthor.title_id +FROM + authors +LEFT JOIN + titleauthor +ON + authors.au_id = titleauthor.au_id; + +/*ADDIND THE OTHER TABLES*/ + +SELECT + authors.au_id AS Author_ID, + authors.au_lname AS Last_name, + authors.au_fname AS First_Name, + titles.title AS Title, + publishers.pub_name AS Publisher +FROM + authors +LEFT JOIN + titleauthor +ON + authors.au_id = titleauthor.au_id +LEFT JOIN + titles +ON + titleauthor.title_id = titles.title_id +LEFT JOIN + publishers +ON + titles.pub_id = publishers.pub_id; + +/* CHALLENGE 2 */ + +SELECT + authors.au_id AS Author_ID, + authors.au_lname AS Last_name, + authors.au_fname AS First_Name, + publishers.pub_name AS Publisher, + COUNT(titles.title_id) AS Title_count +FROM + authors +LEFT JOIN + titleauthor +ON + authors.au_id = titleauthor.au_id +LEFT JOIN + titles +ON + titleauthor.title_id = titles.title_id +LEFT JOIN + publishers +ON + titles.pub_id = publishers.pub_id +GROUP BY +authors.au_id, authors.au_lname, authors.au_fname, publishers.pub_name; + +/* CHALLENGE 3 */ + +SELECT + authors.au_id AS Author_ID, + authors.au_lname AS Last_name, + authors.au_fname AS First_name, + COALESCE(SUM(sales.qty), 0) AS total_sales +FROM + authors +LEFT JOIN + titleauthor ON titleauthor.au_id = authors.au_id +LEFT JOIN + titles ON titles.title_id = titleauthor.title_id +LEFT JOIN + sales ON sales.title_id = titles.title_id +GROUP BY + authors.au_id, authors.au_lname, authors.au_fname +ORDER BY + total_sales DESC +LIMIT 3; + +/* CHALLENGE 4 */ + +SELECT + authors.au_id AS Author_ID, + authors.au_lname AS Last_name, + authors.au_fname AS First_name, + COALESCE(SUM(sales.qty), 0) AS total_sales +FROM + authors +LEFT JOIN + titleauthor ON titleauthor.au_id = authors.au_id +LEFT JOIN + titles ON titles.title_id = titleauthor.title_id +LEFT JOIN + sales ON sales.title_id = titles.title_id +GROUP BY + authors.au_id, authors.au_lname, authors.au_fname +ORDER BY + total_sales DESC; \ No newline at end of file